5

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.

Dave
  • 218
  • 2
  • 10
  • The message you are seeing is expected with CustomErrors turned on - what happened with CustomErrors turned off? – Greg Sansom Jun 07 '11 at 00:04

1 Answers1

12

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.

37Stars
  • 2,489
  • 20
  • 23