首页 > 代码库 > SharePoint开发 - 自定义页面(错误页、登出页)

SharePoint开发 - 自定义页面(错误页、登出页)

本文叙述如何自定义SharePoint的固有页面,比较简单,用一句话说就是“做个页面,写一句代码。”

创建SharePoint空解决方案,添加Layouts映射文件夹,添加页面文件error.aspx和signout.aspx。

error.aspx

 

[html] view plaincopyprint?技术分享技术分享
  1. <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>  
  2. <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>  
  3. <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"  
  4.     Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
  5. <%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
  6. <%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>  
  7. <%@ Import Namespace="Microsoft.SharePoint" %>  
  8. <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
  9.   
  10. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="error.aspx.cs" Inherits="CustomPages.error"  
  11.     DynamicMasterPageFile="~masterurl/default.master" %>  
  12.   
  13. <asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">  
  14. </asp:Content>  
  15. <asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">  
  16.     出现错误,请联系管理员  
  17.     <!--自定义错误页面,在此页面写代码-->  
  18. </asp:Content>  
  19. <asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">  
  20.     应用程序页  
  21. </asp:Content>  
  22. <asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"  
  23.     runat="server">  
  24.     我的应用程序页  
  25. </asp:Content>  

signout.aspx

 

[html] view plaincopyprint?技术分享技术分享
  1. <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>  
  2. <%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>  
  3. <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"  
  4.     Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
  5. <%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
  6. <%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>  
  7. <%@ Import Namespace="Microsoft.SharePoint" %>  
  8. <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>  
  9.   
  10. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="signout.aspx.cs" Inherits="CustomPages.signout"  
  11.     MasterPageFile="~/_layouts/simple.master" %>  
  12.   
  13. <asp:Content ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">  
  14.     <SharePoint:EncodedLiteral runat="server" Text="<%$Resources:wss,signout_pagetitle%>"  
  15.         EncodeMethod=‘HtmlEncode‘ />  
  16. </asp:Content>  
  17. <asp:Content ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server">  
  18.     <SharePoint:EncodedLiteral runat="server" Text="<%$Resources:wss,signout_pagetitle%>"  
  19.         EncodeMethod=‘HtmlEncode‘ />  
  20. </asp:Content>  
  21. <asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">  
  22.     <script type="text/javascript">  
  23.         function ULSd63() { var o = new Object; o.ULSTeamName = "Microsoft SharePoint Foundation"; o.ULSFileName = "SignOut.aspx"; return o; }  
  24.         function _spBodyOnLoad() {  
  25.             ULSd63: ;  
  26.             window.close();  
  27.         }  
  28.     </script>  
  29. </asp:Content>  
  30. <asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">  
  31.     <asp:Label ID="lbPageDescription" Text="<%$Resources:wss,signout_pagedescription%>"  
  32.         runat="server" />  
  33. </asp:Content>  

自定义页面的好处是可以处理一些自己实际中需要的操作。

然后添加feature,激活和取消激活事件

 

[csharp] view plaincopyprint?技术分享技术分享
  1. public override void FeatureActivated(SPFeatureReceiverProperties properties)  
  2.         {  
  3.             SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;  
  4.             if (null != webApp)  
  5.             {  
  6.                 webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, "/_layouts/SP_MIP/CustomPages/error.aspx");  
  7.                 webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Signout, "/_layouts/SP_MIP/CustomPages/signout.aspx");  
  8.                 webApp.Update(true);  
  9.             }  
  10.         }  
  11.   
  12.         public override void FeatureDeactivating(SPFeatureReceiverProperties properties)  
  13.         {  
  14.             SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;  
  15.             if (null != webApp)  
  16.             {  
  17.                 webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, null);  
  18.                 webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Signout, null);  
  19.                 webApp.Update(true);  
  20.             }  
  21.         } 

SharePoint开发 - 自定义页面(错误页、登出页)