
Customizing Application Pages
231
Registering Custom Application Pages from Receivers
Using the SharePoint 2010 API, you can programmatically set the URL of a custom page that
replaces one of the default SharePoint application pages using a SharePoint Web Application feature.
The following pages can be replaced in code:
SPWebApplication.SPCustomPage.AccessDenied
SPWebApplication.SPCustomPage.Confirmation
SPWebApplication.SPCustomPage.Error
SPWebApplication.SPCustomPage.Login
SPWebApplication.SPCustomPage.RequestAccess
SPWebApplication.SPCustomPage.Signout
SPWebApplication.SPCustomPage.WebDeleted
The following code listings are examples of the FeatureActivated and FeatureDeactivating methods for
replacing the RequestAccess application page. The FeatureActivated method sets the RequestAccess
page to a custom access page called
MyCustomPage.aspx when the feature is activated. The
FeatureDeactivating method sets the RequestAccess page back to the normal default page.
LISTING84: FeatureActivated Event Receiver Code Sample to Set the RequestAccess Page to
Your Custom Page
public override void FeatureActivated
(SPFeatureReceiverProperties properties)
{
if (properties == null) throw new ArgumentNullException(“properties”);
SPWebApplication webApp = properties.Feature.Parent as
SPWebApplication;
if (webApp != null)
{
webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.RequestAccess, ...