MVC HandleError 返回错误 500 并查看错误页面
我正在将 MVC 3 与 VS2010 一起使用,并尝试让 [HandleError] 工作。我在控制器中创建了一个测试来模拟崩溃,如下所示:
[HandleError]
public ActionResult Crash()
{
throw new ApplicationException();
}
还进入 web.config 并添加:
<customErrors mode="on" />
如果我从 Chrome 运行,MVC 将返回 Shared/Error.aspx 中的视图,因此这项工作正常。
如果我从 IE 8 运行,我会收到其友好的错误页面(“网站无法显示该页面,最可能的原因:...您可以尝试什么...”)。我进入 IE 工具并关闭“显示友好的 HTTP 错误消息”并再次运行,IE 显示我的 Error.aspx 视图。显然我无法让用户更改此设置,但至少我知道我的 Error.aspx 正在被返回。
因此,我运行 Fiddler,当我让浏览器转到我的 Crash 方法时,它显示即使 MVC 返回我的 Error.aspx 视图,它也会返回 500 的结果。这会导致 IE 认为它有错误并用其友好页面覆盖我的页面。
我认为 MVC 应该在我的 Error.aspx 页面中返回结果 200,而不是 500。任何人都可以给我一些关于尝试什么的想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你的错误页面> 512字节,应该可以正常工作。 这只是 IE 一如既往的不体贴的猪。
If you make your error page > 512 bytes, it should work fine. It's just IE being an inconsiderate swine, as ever.