asp.net MVC 3的HandleError全局过滤器总是显示IIS状态500页 [英] asp.net mvc 3 handleerror global filter always shows IIS status 500 page

查看:113
本文介绍了asp.net MVC 3的HandleError全局过滤器总是显示IIS状态500页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了一切,即使在卸载asp.net MVC3,我不能得到的HandleError全局过滤器的工作。

I have tried everything, even uninstalling asp.net mvc3, and I can't get HandleError global filter working.

我已经建立了在Global.asax中的HandleError过滤器:

I have set up the HandleError filter in the Global.asax:

 public static void RegisterGlobalFilters(GlobalFilterCollection filters)
 {
     filters.Add(new HandleErrorAttribute());
 }

我也有启用的customErrors(如果我设置的defaultRedirect =错误不要紧与否,我认为这是在文档,因为需要对旧版本的MVC):

Also I have CustomErrors enabled (it does not matter if i set defaultRedirect="Error" or not, I think that is in the docs because is needed for older versions of mvc):

<customErrors mode="On" />

试图通过网页浏览,直至错误得到提高,无论您从本地主机或使用主机名做,开发服务器内部或IIS 7.5,它总是重定向到一个标准的状态500页面,而不是我的自定义Error.cshtml认为我在共享创建。这是错误观点code:

Trying to navigate through the page until the error gets raised, wether you do from localhost or using the hostname, inside the development server or IIS 7.5, it always redirects to a standard status 500 page, instead of my custom Error.cshtml view that I have created in Shared. Here is Error view code:

@model System.Web.Mvc.HandleErrorInfo

@{
    ViewBag.Title = "Oooops";
}

<h2>Ooops Something really bad happened!</h2>

此外,我注意到,如果我创建一个新的ASP.NET MVC3项目,然后选择Internet应用程序的模板,并在该项目刚刚启用的customErrors,那么过滤器的HandleError开始工作得很好,但是使用空MVC3模板没有。

Also I have noted that if I create a new ASP.NET MVC3 project and then select "Internet Application" template, and just enabling customErrors in that project, then the HandleError filter starts working just fine, however using the empty MVC3 template does not.

我要澄清一下,确实我可以看到的错误观点被处理时调试,但是浏览器总是显示错误500页。

I want to clarify, that indeed I can see the error view being processing when debugging, however the browser always display Error 500 page.

推荐答案

我遇到了同样的问题。我发现这个职位:在asp.net mvc的 500内部服务器错误一>,并试图取消选中友好HTTP错误和我HandleErrors属性开始工作按预期在IE 8与IE检查7兼容模式(和开始工作像它在Chrome的默认操作)。我不认为这是一个应用程序部署一个有效的解决方案,但也许有那么它重定向到一个错误的控制器,而不只是默认的错误观点,延长的HandleError属性的方法。

I ran into this same issue. I found this post: 500 Internal Server Error in asp.net mvc and tried unchecking "Friendly Http Errors" and my HandleErrors attribute started working as expected in IE 8 with IE 7 compatibility mode checked (and started working like it does in Chrome by default). I don't think this is a valid solution for a deployed app, but perhaps there's a way to extend the HandleError attribute so that it redirects to an "Error" controller instead of just the default Error view.

更新:这个帖子表示会返回一个HTTP状态500时,IE浏览器处理它笨拙。绕过它的一种方式,是将状态设置为200,那么一切似乎工作正常(甚至在IE)。

UPDATE: This post shows that when an HTTP Status 500 is returned, IE handles it awkwardly. A way to get around it, is to set the Status to 200, then everything seems to work OK (even in IE).

public class CustomHandleErrorAttribute : HandleErrorAttribute
{
    public override void OnException(ExceptionContext filterContext)
    {    
        base.OnException(filterContext);

        //http://stackoverflow.com/questions/5137627/mvc-handleerror-returns-error-500-and-view-error-page
        //http://stackoverflow.com/questions/183316/asp-net-mvc-handleerror
        filterContext.HttpContext.Response.StatusCode = 200;
    }
}

这篇关于asp.net MVC 3的HandleError全局过滤器总是显示IIS状态500页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆