Override existing Application Pages (Error.aspx, Login.aspx,AccessDenied.aspx ) with Custom in SharePoint 2010

With SharePoint 2010 you can now set your own custom error pages by overriding out-of-box application pages like

AccessDenied.aspx, Confirmation.aspx, Error.aspx, Login.aspx, ReqAcc.aspx, SignOut.aspx etc. Various methods like UpdateMappedPage, GetMappedPage have been introduced to facilitate this.

Following are the Pages that you can override

Page Name Description
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.

Lets look at an Example to Override Existing Error.aspx with your Own custom page using UpdateMappedPage method.

Method -

UpdateMappedPage(SPWebApplication.SPCustomPage.pageName,yourCustomPage)
pageName - e.g. AccessDenied, Error, Login

yourCustomPage - This should be the url for your custom page in Layouts folder. This must start with “/_layouts/”. To remove the mapping to the custom page, set the value to null.

Return Value - This returns true if the custom application page is successfully mapped; otherwise, false.

Usage -

webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, “/_layouts/CustomErrorPage/CustomErrorPage.aspx”);

To Remove the Mapping and reset to default -

webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, null);

To get the Page currently being Used you can use the GetMappedPage method.

Method -
GetMappedPage(SPWebApplication.SPCustomPage.pageName or yourCustomPage Location)
pageName - e.g. AccessDenied, Error, Login

Custom Page Location- This should be the url for your custom page in Layouts folder. This must start with “/_layouts/”. To remove the mapping to the custom page, set the value to null.

Return Value - The location of the customized application page. Otherwise, null.

Usage –

webApp.GetMappedPage(SPWebApplication.SPCustomPage.Error)

or

webApp.GetMappedPage(“/_layouts/CustomErrorPage/CustomErrorPage.aspx”)

Related Posts

Disclaimer: The contents of this site are provided “AS IS”. Information and views expressed including URL(s) and other Internet website references, may change without notice. You bear the risk of using it. SharePoint, MOSS, SharePoint 2010, SharePoint 2013 and Microsoft are trademarks of the Microsoft Corporation.Learning SharePoint only provides Tips,Tricks and Tutorials for using Microsoft SharePoint, Microsoft Office and related Softwares.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.