如何建立自訂Sharepoint 應用程式頁 (Creating an Application Page in Windows SharePoint Services 3.0)

來源:互聯網
上載者:User

 應用程式頁(也稱作“_ layouts”頁)儲存在C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/LAYOUTS目錄中。IIS中對應的虛擬目錄為:_layouts.

 

應用程式頁使用application.master主版頁面,並繼承Microsoft.SharePoint.WebControls.LayoutsPageBase,此頁面只有認證通過並有一定的授權的使用者才能訪問。

一個簡單的應用程式頁如下所示:

  1. <%@ Assembly Name="Microsoft.SharePoint,Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
  2. <%@ Page Language="C#" MasterPageFile="~/_layouts/application.master"  
  3. Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %>
  4. <%@ Import Namespace="Microsoft.SharePoint" %>
  5. <script runat="server">
  6.   protected override void OnLoad(EventArgs e) 
  7.   {
  8.         SPWeb web = SPContext.Current.Web ;
  9.         SPUser currentUser = web.CurrentUser;
  10.         lblUserName.Text = currentUser.Name;
  11.         lblUserLogin.Text = currentUser.LoginName;
  12.         lblUserEmail.Text = currentUser.Email;  
  13.   }
  14. </script>
  15. <asp:Content ID="Main" contentplaceholderid="PlaceHolderMain" runat="server">
  16.   <table border="1" cellpadding="4" cellspacing="0" style="font-size:12">
  17.     <tr>
  18.       <td>CurrentUserName:</td>
  19.       <td><asp:Label ID="lblUserName" runat="server" /></td>
  20.     </tr>
  21.     <tr>
  22.       <td>CurrentUserLogin:</td>
  23.       <td><asp:Label ID="lblUserLogin" runat="server" /></td>
  24.     </tr>
  25.     <tr>
  26.       <td>CurrentUserEmail:</td>
  27.       <td><asp:Label ID="lblUserEmail" runat="server" /></td>
  28.     </tr>
  29.   </table>
  30. </asp:Content>
  31. <asp:Content ID="PageTitle" runat="server"
  32.              contentplaceholderid="PlaceHolderPageTitle" >
  33.   Hello World
  34. </asp:Content>
  35. <asp:Content ID="PageTitleInTitleArea" runat="server"
  36.              contentplaceholderid="PlaceHolderPageTitleInTitleArea" >
  37.   The Quintessential 'Hello World' Application Page
  38. </asp:Content>

另:_layout下的頁面也可以不繼承Sharepoint的類,

如:

 

  1. <%@ Page Language="C#" %>
  2. <%@ Assembly Name="Microsoft.SharePoint,Version=12.0.0.0, Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
  3. <%@ Import Namespace="Microsoft.SharePoint" %>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <script runat="server">
  6.   protected override void OnLoad(EventArgs e) 
  7.   {
  8.         SPWeb web = SPContext.Current.Web ;
  9.         SPUser currentUser = web.CurrentUser;
  10.         lblUserName.Text = currentUser.Name;
  11.         lblUserLogin.Text = currentUser.LoginName;
  12.         lblUserEmail.Text = currentUser.Email;  
  13.   }
  14. </script>
  15. <html xmlns="http://www.w3.org/1999/xhtml" >
  16. <head runat="server">
  17.     <title>無標題頁</title>
  18. </head>
  19. <body>
  20.     <form id="form1" runat="server">
  21.     <div>
  22.      <table border="1" cellpadding="4" cellspacing="0" style="font-size:12">
  23.     <tr>
  24.       <td>CurrentUserName:</td>
  25.       <td><asp:Label ID="lblUserName" runat="server" /></td>
  26.     </tr>
  27.     <tr>
  28.       <td>CurrentUserLogin:</td>
  29.       <td><asp:Label ID="lblUserLogin" runat="server" /></td>
  30.     </tr>
  31.     <tr>
  32.       <td>CurrentUserEmail:</td>
  33.       <td><asp:Label ID="lblUserEmail" runat="server" /></td>
  34.     </tr>
  35.   </table>
  36.     </div>
  37.     </form>
  38. </body>
  39. </html>

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.