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.

1
  • The message you are seeing is expected with CustomErrors turned on - what happened with CustomErrors turned off? Commented Jun 7, 2011 at 0:04

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.