MVC HandleError returns error 500 and view error page

ⅰ亾dé卋堺 提交于 2019-12-23 18:52:52

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/5137627/mvc-handleerror-returns-error-500-and-view-error-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!