Subscribe

RSS Feed (xml)

Configuring Application Error Handling

The web.config file includes a


<customErrors ...> section that controls how the application


responds to errors on its pages. A typical customErrors section follows:


<customErrors mode="RemoteOnly" defaultRedirect="/Maintenance.aspx" >


<error statusCode="404" redirect="/NotFound.aspx" />


</customErrors>


The settings are case-sensitive.The first attribute, mode, can be On, Off, or RemoteOnly.


The first two are self-explanatory; the third redirects errors only for non-local users, so


that a local developer can still debug problems without being routed to the "friendly"


error page.The second attribute, defaultRedirect, specifies the page to which any


request that results in an unhandled exception is sent. If it is not set but custom errors


are on, users will see a generic error message (instead of the detailed exception information).


Optionally, specific redirects can be set up for individual error codes by adding


<error ...> elements within the customErrors element. Each of these can specify a


statusCode, such as 404, that maps to a file not found error code, or 500, for a generic


application error. Each error code can be mapped to its own specific error page by setting


the path to the page in the redirect attribute.


Comments


Setting up friendly default error pages for ASP.NET applications and their common


errors is fairly straightforward. It is useful to have the default error page write to a log


with details of the request or URL that caused the problem. It can also be useful to log


which files users are requesting that are resulting in 404s, and ideally to have the 404


error page automatically redirect users to new locations of old resources.


Note, however, that these error pages handle requests only for resources that the


ASP.NET engine is registered to handle. So a request for a missing .ASPX file would


result in the 404 page being called, but by default a request for a nonexistent .HTM or


.GIF file would not. Additional file types can be associated with the ASP.NET process in


IIS, but this imposes a performance penalty. Note that most of this functionality is also


available within IIS.

No comments:

Archives

Variety in the Web World