ErrorPage.aspx Page

Description: The ErrorPage.aspx page provides a custom error message that is displayed to users anytime an unhandled exception occurs within the application. Click the above links to view source/information about the various components/user controls/stored procedures used to build it.

Implementation Notes: Custom error handling is a built-in feature of ASP.NET. To enable this feature, Adventure Works Cycles simply added a "customErrors" configuration section to the Adventure Works Cycles's web.config file:

    <customErrors mode="On" defaultRedirect="ErrorPage.aspx"/>


This configuration entry indicates that the "ErrorPage.aspx" page should be used by default whenever an unhandled exception occurs during the application.  Although we are not taking direct advantage of it here, we could have optionally added additional entries to send different error messages back to the client depending on the type of errors that occurred: 


    <customErrors mode="On" defaultRedirect="ErrorPage.aspx">
        <error statusCode="404" redirect="adminmessage.htm"/>
        <error statusCode="403" redirect="noaccessallowed.htm"/>
    </customErrors>


For example, the above configuration settings indicate that browsers should be redirected to the "adminmessage.htm" page when an HTTP Status Code of 404 is returned (for example: a missing file).  It also indicates that browsers should be redirected to "noaccessallowed.htm" when an HTTP Status Code of 403 is returned (for example: an illegal attempt to access a resource).

The <customErrors> configuration section also supports a "mode" attribute that supports three values: "Off", "On", and "RemoteOnly".  "Off" will disable custom errors and instead send back an exception stack trace when an unhandled exception occurs.  Although this is very useful when debugging applications, it is not very user-friendly for customers.  "On" indicates that custom error pages should always be used -- for all clients.  "RemoteOnly" is a hybrid mode that will ensure that customers who browse the application from a remote machine will see custom error messages, whereas users on the local server machine (for example: administrator and developers) will see detailed error stack traces.