加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – HandleError属性没有任何效果

发布时间:2020-12-16 04:10:10 所属栏目:asp.Net 来源:网络整理
导读:在我的web.config中,我包括: customErrors mode="On" / 现在黄色的死亡屏幕不再显示了. 我以为我必须将HandleError属性包含在我的控制器方法或类本身中: [HandleError]public ActionResult About(){ throw new Exception("Just an exception"); return Vie
在我的web.config中,我包括:
<customErrors mode="On" />

现在黄色的死亡屏幕不再显示了.
我以为我必须将HandleError属性包含在我的控制器方法或类本身中:

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

但它没有任何影响,它与以下相同:

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

在这两种情况下都会显示自定义错误页面.那么HandleError属性又是什么呢?

解决方法

如果在MVC项目的App_Start文件夹下的FilterConfig.cs包含以下内容,则会发生这种情况:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new HandleErrorAttribute());
}

由于在应用程序启动时注册了HandleError过滤器,因此您不必使用此属性修饰每个控制器操作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读