I have an MVC4 site with a nice customError page that works great if you have friendly errors turned off in IE but doesn’t show if you have friendly errors turned on. I don’t know why MVC4 would return a 500 when it should just show my error page, but there it is. Here is an example (I had to make it code because SO flipped out at the IP number):
http://192.52.51.45/web/Trip/Index/f32e4bc5-9e06-4bb8-8d43-d43b8c9a014c
What is the configuration change I need to make to have the site return a 200 and just show my error page? Right not the only change I have from the default Web.config is the customErrors:
<customErrors mode="On" />
Thanks for the help.
That’s how the
[HandleError]global attribute is implemented:Notice how it sets the status code to 500 and renders the
~/Views/Shared/Error.cshtmlview. All this happens when custom errors are enabled.And this by the way is the semantically correct HTTP status code to be used in this exceptional case. Or 404 if you haven’t found the requested resource. 200 should be used only if the server successfully processed the user request.
If for some reason you don’t like this behavior you could always write a custom global error handling attribute and replace the default one (which is registered inside
~/App_Start/FilterConfig.cs->filters.Add(new HandleErrorAttribute());).