Default MVC Redirect Error Error Page Not Always Displayed

I have a custom error page in my MVC application that is just ~ / error /, but when I return user errors in Web.Config like this:

<customErrors mode="On" defaultRedirect="~/error/" /> 

It only works on 400 errors, not 500 server errors, and instead gives me the following error message on a white page:

"An error occurred while processing your request."

How can I just make every mistake on the DefaultRedirect page?

+4
source share
1 answer

500 errors must be handled by the MVC application itself. User errors defined by web.config refer to errors other than 500 errors.

Basically, you need to use the RegisterGlobalFilter method (in global.asax ) to add a new HandleErrorAttribute collection to the filter collection (you name the view that will be used for errors in HandleErrorAttribute), and then create one that takes System.Web.Mvc.HandleErrorInfo as its model System.Web.Mvc.HandleErrorInfo . There is no controller that handles these errors or sends the model to the view, so you cannot just redirect to the error page.

You can get more information at http://community.codesmithtools.com/CodeSmith_Community/b/tdupont/archive/2011/03/01/error-handling-and-customerrors-and-mvc3-oh-my.aspx .

EDIT There is an alternative method where all errors are handled using the MVC shown in How to display custom error pages in Asp.Net Mvc 3? . Basically, you set up protected void Application_Error() in the global.asax file to handle all errors without going through web.config.

+3
source

All Articles