2
votes

How do we customize the error pages for the following in SharePoint:

Bad request 400

Unauthorized 401

Forbidden 403

Not found 404 (Solved through SharePoint 404)

Internal Error 500

Not implemented 501

Service not available 503

While I know how to customize the 404 page, how and what is the best way to customize the other error pages listed?

Through web.config? Separate console app? Stsadm commands?

1

1 Answers

0
votes

For SharePoint 2010, the following blog posts present some solutions to creating custom error pages:

The custom error pages can be activated via feature with the following code-snippet:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
        if (null != webApp)
        {
            if(!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, CustomErrorPage))
            {
                throw new ApplicationException("Cannot create new error page mapping !!");
            }
            webApp.Update(true);
        }
    }


    public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
    {
        SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
        if (null != webApp)
        {
            if (!webApp.UpdateMappedPage(SPWebApplication.SPCustomPage.Error, null))
            {
                throw new ApplicationException("Cannot reset error page mapping");
            }
            webApp.Update(true);
        }
    }

For SharePoint Server 2007, the recommended approach is to create a custom HttpModule as explained in the following blog post: