razorasp.net-mvc-4handleerror

Does HandleError work anymore in Asp.net MVC 4 with razor


I have the [HandleError] attribute set on my controller.

This is my action method:

    public ActionResult ShowError()
    {

        throw new NullReferenceException();
        return View();
    }

This action method has a corresponding view.

I have set custom errors in the config

<customErrors mode="On">     
</customErrors>

I have the Error.cshtml file in the shared folder under Views folder.

Now navigating to the ShowError controller method brings up this window in my IDE enter image description here

On hitting F5 I get this in my browser window instead of the Error page from the shared folder. enter image description here

What else is needed to be done to show the error page? How do I get the HandleError to work?

Thanks


Solution

  • Ok. So the problem was the browser I was using, which is IE 9. IE 9 seems to have problems showing an error page that is less than one KB. I put @(new String(' ', 1000)) at the end of my error page and got it working.