在我的 web.config 中,我包含了:
<customErrors mode="On" />
现在不再显示死亡蓝屏了。 我想我必须将 HandleError 属性包含到我的 Controller 方法或类本身中:
[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 过滤器是在应用程序启动时注册的,因此您不必使用此属性来装饰每个 Controller 操作。
关于asp.net-mvc - HandleError 属性没有任何作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17917434/