I have an MVC 2 web application, which is nearing release. Until now I have had custom errors turned off but I would like them working when I go production ready.
I have set up my web.config with the following:
<customErrors mode="On" defaultRedirect="/Error/">
<error statusCode="404" redirect="/Error/NotFound "/>
</customErrors>
The 404 one works perfectly, and NotFound is an action which maps directly to a View that just shows a pretty standard 404 page using my own Site.Master file.
For anything other than a 404, I want a user to be able to view the exception details. (This is an internal application, and there is no security risk in doing so).
The Error
default action Index
is set to return a View() which I have defined. What I cannot figure out is how to pass the exception information into the View?
This looked promising:
http://devstuffs.wordpress.com/2010/12/12/how-to-use-customerrors-in-asp-net-mvc-2/
But when I use the View with:
<%@ Page Title="" Language="C#"
MasterPageFile="~/Views/Shared/Bootstrap.Master"
Inherits="System.Web.Mvc.ViewPage<System.Web.Mvc.HandleErrorInfo>" %>
The error page itself throws an error, as HandleErrorInfo is null. Obviously an error in the custom error causes MVC2 a whole host of problems, and the result is a yellow screen of death.
I guess either I missed something key in the blog, or it doesn't explain how to get the HandleErrorInfo to be anything other than null without setting the Error attribute for every single one of my Controllers/Actions.
Also, I am aware that MVC3 deals with this better, and I am aware Razor is very good. It has not been used for this project nor will this project be changed to use it. So please no "Use MVC3" answers.