How to Change System Application Pages (Like AccessDenied.aspx, Signout.aspx etc)


Hi All,

An advantage of SharePoint 2010 over SharePoint 2007 is, we can programatically change the URL of System Application Pages. For Example, It was not very easy to change the URL of AccessDenied.aspx page in SharePoint 2007 but in SharePoint 2010 we can easily change the URL with just few lines of code.

For this purpose we have two methods available:

  • GetMappedPage
  • UpdateMappedPage: returns true if the custom application page is successfully mapped; otherwise, false.


You can override following pages.


  • AccessDenied, Specifies AccessDenied.aspx.
  • Confirmation, Specifies Confirmation.aspx.
  • Error, Specifies Error.aspx.
  • Login, Specifies Login.aspx.
  • RequestAccess, Specifies ReqAcc.aspx.
  • Signout, Specifies SignOut.aspx.
  • WebDeleted, Specifies WebDeleted.aspx.


( http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.spcustompage.aspx )


using (SPSite site = new SPSite(http://testserver01))
 {
   //Get a reference to the web application.
   SPWebApplication webApp = site.WebApplication;
   webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied,"/_layouts/customPages/CustomAccessDenied.aspx");
   webApp.Update();
 }

Similarly, you can use  SPCustomPage.Confirmation, SPCustomPage.Error, SPCustomPage.Login, SPCustomPage.RequestAccess, SPCustomPage.Signout and SPCustomPage.WebDeleted to override these pages.

To  reset the mapping, set the Target value to Null like

webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied,null);
webApp.Update();


One restricted to location in the /_layouts folder. When updating the mapped page, the URL has to start with "/_layouts/".


Ref:

  • http://msdn.microsoft.com/en-us/library/gg512103.aspx#bk_spcustapp
  • http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spwebapplication.updatemappedpage.aspx




Jayant Sharma



Comments