I have a custom error page in my MVC application that’s just ~/error/ but when I turn Custom Errors on in the Web.Config like so:
<customErrors mode="On" defaultRedirect="~/error/" />
It only works for 400 errors not server-side 500 errors and instead gives me the following error message on a white page:
“Sorry, an error occurred while processing your request.”
How can I just make every single error go to the defaultRedirect page?
500 errors should be handled by the MVC application itself. Custom Errors defined by the
web.configare for errors other than 500 errors.Basically, you need to use the
RegisterGlobalFiltermethod (inglobal.asax) to add a newHandleErrorAttributeto the filter collection (you’ll name the view to use for errors in the HandleErrorAttribute), then create a view that takes as its modelSystem.Web.Mvc.HandleErrorInfo. There is no controller that handles these errors or sends the model to the view, so you can’t just redirect to your 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 through MVC, shown in How do I display custom error pages in Asp.Net Mvc 3?. Basically, you set up a
protected void Application_Error()in your global.asax file to handle all errors, without going through web.config.