Error pages usage and configuration

Displaying error message in ASP.NET and IIS is trickier that it seems. There are two separate error page mechanisms (one in IIS and one in ASP.NET). Getting the second one to work properly (including returning the proper HTTP status code) is quite tricky. This library contains unified error handling for IIS and ASP.NET errors.


Register configuration section

Include the following section registration in your web.config file:
    <sectionGroup name="altairis.web">
        <section name="management" type="Altairis.Web.Management.Configuration.ManagementSection, Altairis.Web.Management"/>

Register HTTP module

Register the ErrorHandlingModule HTTP module (used also by exception mailing, so register it only once):
        <add name="ErrorHandlingModule" type="Altairis.Web.Management.ErrorHandlingModule, Altairis.Web.Management" />

Do not configure any error handling options

There is no need to set neither system.web/httpErrors nor system.webServer/httpErrors configuration, since the module processes both types of errors.

Configure the error pages

This is minimal configuration to get the exception mailing up and running - just enable it:
        <errorPages enabled="true" />
Possible attributes of the errorPages element:
Name Default value Description
enabled false Set to true to enable error pages.
excludeLocalRequests true Ignore requests coming from the same computer (useful for development).
fallbackErrorCode 500 Error page to use when no specific page is found for given status. Any integer from 400 to 599.
folderName ~/App_Data/ErrorPages/ Folder, where error pages are located. May be virtual path starting with ~ or full physical path.

Error Pages

This module decides which HTML page would be displayed based on HTTP status code set by previous modules and handlers. Status codes 400-599 with exception of 401 (used for authentication) are processed.
The modulee tries to find file named according to status code, with .htm extension. Ie. in default configuration and for 404 error, it tries to find file named ~/App_Data/ErrorPages/404.htm. If the file is found, its content is returned to user.

If file is not found, file derived from fallbackErrorCode is used instead (ie. ~/App_Data/ErrorPages/500.htm). If even this file is not found, the module gives up and the default error page configured otherwise is displayed.

In minimal configuration, 404 and 500 error pages are recommended. Selection of error pages can be found in NuGet package and sample application. If you want to use default IIS files, copy the appropriate files from C:\InetPub\custerr\your-locale.

Last edited Jul 4, 2011 at 12:43 AM by altair, version 1


No comments yet.