Search
Categories
Navigation
Twitter Updates

Twitter Updates

    follow me on Twitter
    « So, You Want to Learn ASP.NET MVC? | Main | DevLink: ASP.NET MVC Patterns & Anti-Patterns »
    Wednesday
    Aug262009

    Custom Error Pages in ASP.NET MVC

    Computer displaying a blue screen of death - Photo by: russeljsmith (Flickr) Disclaimer: This is a bit of a reminder post to myself, but it may help others as well.

    When writing an ASP.NET MVC application, the need to gracefully handle errors (including HTTP 404 errors) will come up sooner or later. As with other aspects of MVC, an important thing to remember is that it’s just a new layer of abstraction on top of ASP.NET so the classic ways of handling errors are all present in MVC, as well as a few new options.

    Once again, though, others have already done a good job documenting the various approaches, so I’ll link to that content rather than repeat it:

    These should give you some sense to the possible approaches for handling errors in MVC. I’ve found Barry’s post particularly helpful for my needs so far, with one exception (which is the self-reminder part of this post). Barry outlined a way to disable IIS7 custom errors using the IIS7 administration interface, but, depending on your hosting environment, you may not have access to this UI. Fortunately, you can change IIS’ error mode using the system.webServer/httpErrors node.

    To disable IIS’ custom errors and use detailed error pages (those which you’ve defined for you application) add the following to the system.webServer section in your application’s root Web.config file.

    <system.webServer>
      <httpErrors errorMode="Detailed" />
      ... other settings ...
    </system.webServer>
    Of course, this only works on IIS7+, but you should now see the error pages you’ve defined for your application instead of the IIS ones.

    PrintView Printer Friendly Version

    EmailEmail Article to Friend

    Reader Comments

    There are no comments for this journal entry. To create a new comment, use the form below.

    PostPost a New Comment

    Enter your information below to add a new comment.

    My response is on my own website »
    Author Email (optional):
    Author URL (optional):
    Post:
     
    Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>