I have a new asp.net mvc 3 website with the razor engine and am trying to get the site ready for production where I cannot have the Yellow Screen of Death come up. In webforms this is easy, just turn on customErrors in the web.config and you are done.
To test I setup a test controller method as such:
public ActionResult Ex()
{
throw new InvalidOperationException();
}
I expected the error view (/Views/Shared/Error.cshtml) to be displayed instead I get the Yellow Screen of Death with the message "Operation is not valid due to the current state of the object." I tried turning on customErrors in the web.config and it still does not work. I am calling the RegisterGlobalFilters method in the Global.asax but have also tried applying the HandleError attribute directly.
Thanks for your help.
Turn on the custom errors and route them to an Error controller.
<customErrors mode="On" defaultRedirect="~/Error/Unknown">
<error statusCode="403" redirect="~/Error/NoAccess" />
<error statusCode="404" redirect="~/Error/NotFound" />
</customErrors>
The controller needs the actions Unknown, NoAccess, and NotFound. Each will need to return a view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With