User error page in asp.net mvc 3

I have a new asp.net mvc 3 website with a razor engine and am trying to prepare the site for production where I cannot have a yellow screen of death. In webforms, this is easy, just include customErrors in web.config and you're done.

For testing, I configure the 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 a yellow death screen with the message "Operation is invalid due to the current state of the object." I tried including customErrors in web.config and it still does not work. I call the RegisterGlobalFilters method in Global.asax, but also tried to apply the HandleError attribute directly.

Thank you for your help.

+5
1

.

<customErrors mode="On" defaultRedirect="~/Error/Unknown">
  <error statusCode="403" redirect="~/Error/NoAccess" />
  <error statusCode="404" redirect="~/Error/NotFound" />
</customErrors>

Unknown, NoAccess NotFound. .

+12

All Articles