MVC HandleError returns error 500 and view error page
Asked Answered
P

1

3

I am using MVC 3 with VS2010 and trying to get [HandleError] working. I created a test in the controller to simulate a crash as follows:

[HandleError]
public ActionResult Crash()
{
    throw new ApplicationException();
}

Also went into web.config and added:

<customErrors mode="on" />

If I run from Chrome, MVC returns the view in Shared/Error.aspx, so this work ok.

If I run from IE 8, I get its friendly error page ("The website cannot display the page, Most likely causes: ... What you can try..."). I went into IE Tools and turned off "Show friendly HTTP error message" and run again and IE shows my Error.aspx view. Obviously I can't get users to change this setting, but at least I know my Error.aspx is being returned.

So I run Fiddler, and when I make the browser go to my Crash method, it shows that that even though MVC is returning my Error.aspx view, it is returning 500 for the Result. This causes IE to think it has an error and override my page with its friendly page.

I think MVC should be returning Result 200 with my Error.aspx page and not 500. Can anyone give me some ideas on what to try?

Predestination answered 28/2, 2011 at 2:17 Comment(0)
L
8

If you make your error page > 512 bytes, it should work fine. It's just IE being an inconsiderate swine, as ever.

Leslielesly answered 1/4, 2011 at 10:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.