SharePoint 2007 Custom Error Page
As you may already know SharePoint come out with "friendly" standard error page that does not give sufficient information about error that occurred. Since SharePoint web application presents ASP.NET 2.0 web application it should be easy to set custom error page by changing the web.config file. Unfortunately applying the changes will not take the effect as you expected like they would in pure ASP.NET 2.0 web application.
Fortunately there is an option to avoid seeing that standard SharePoint "friendly" error page by changing several settings in SharePoint web application web.config file. Depending on settings you may see the custom error page you've built or standard ASP.NET error page with full stack trace. During development it is very handy to see standard ASP.NET error page but from user perspective when it come to other environments (staging, acceptance, production) it is better to have error page that has the same look & feel as entire web application.
If you are building a SharePoint web application that is based on publishing site template than you will not be satisfied with out of the box error page since it will significantly differ from look & feel that you've built and also content on that page cannot be updated. For web applications that are based on team site template you will on the other hand usually keep the standard SharePoint error page because it fits in standard team site look & feel. It is important to mention that changing the look & feel of standard SharePoint error page should not be taken into consideration for several reasons, one is that changes will take effect on whole SharePoint server instance and all web applications that are created within that instance, second is any possible Microsoft update that can overwrite your custom changes.
Although this post is not about explaining of how to setup the standard ASP.NET error page still I must start my explanation with it because it is a good starting point for setting the custom error page and since most of the developers already know this.
Default configuration inside one SharePoint web application web.config file:
SafeMode
<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
CustomErrors
<customErrors mode="On" >
In order to see the ASP.NET default error page with full stack trace apply next changes to appropriate SharePoint web application web.config file:
SafeMode
<SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
CustomErrors
<customErrors mode="Off" >
If you just change the CallStack to true you will see the standard ASP.NET error page but without exception details.
In order to see custom error page you've built (i.e. error.aspx) apply next changes to appropriate SharePoint web application web.config file:
SafeMode
<SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">
CustomErrors
<customErrors mode="On" defaultRedirect="/Pages/Error.aspx">
Conclusion is quite simple, in order to have the ability to define custom errors mode and default redirect as you already have with standard ASP.NET applications simply set CallStack on true and you will be able to configure your custom error page.