Original

You are currently reviewing an older revision of this page.
Go to current version
We can create an Feature Receiver were we can use the UpdateMappedPage method to define a custom access denied page

public class SPEventReceiver : SPFeatureReceiver
    {
        Const string AccessDeniedPage = "/_layouts/Pages/AccessDenied.aspx";
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webapp = properties.Feature.Parent as SPWebApplication;
            if (webapp != null)
            {
                if (!webapp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied, AccessDeniedPage)
                {
                    throw new ApplicationException("Cannot create the new Access Denied Page Mappings.");
                }
                webapp.Update(true);
            }
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWebApplication webapp = properties.Feature.Parent as SPWebApplication;
            if (webapp != null)
            {
                if (!webapp.UpdateMappedPage(SPWebApplication.SPCustomPage.AccessDenied, null))
                {
                    throw new ApplicationException("Cannot reset the default Access Denied Page Mappings.");
                }
                webapp.Update(true);
            }
        }
     }

Similarly we can do create custom pages for various events as shown in the below links

http://www.spdeveloper.co.in/articles/pages/custom-error-pages-for-sharepoint2010-sites.aspx
Revert to this revision