的HandleError属性没有任何影响 [英] HandleError attribute doesn't have any effect

查看:205
本文介绍了的HandleError属性没有任何影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的web.config我已经包括:

In my web.config I have included:

<customErrors mode="On" />

现在死亡的黄色屏幕不​​再显示。
我想我必须包含的HandleError属性我控制器方法或类本身:

Now the yellow screen of death isn't shown anymore. I thought I'd have to include the HandleError attribute to my controller methods or the class itself:

[HandleError]
public ActionResult About()
{
    throw new Exception("Just an exception");
    return View();
}

但它没有任何效果,这是一样的:

But it doesn't have any effect, it's the same as:

public ActionResult About()
{
    throw new Exception("Just an exception");
    return View();
}

在这两种情况下显示自定义错误页。那么什么是对的HandleError属性?

In both cases the custom error page is shown. So what is it about the HandleError attribute?

推荐答案

这可能发生,如果FilterConfig.cs的MVC项目App_Start文件夹下,包含:

That can happen if FilterConfig.cs, under App_Start folder of the MVC project, contains:

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

由于过滤器的HandleError注册的应用程序启动时,你不必装饰与此属性的每个控制器动作。

Since the HandleError filter is registered when the App starts, you don't have to decorate each controller action with this attribute.

这篇关于的HandleError属性没有任何影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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