相关疑难解决方法(0)

HandleErrorAttribute不起作用

我在VS10中启动了一个MVC 3模板项目,并修改了global.asax.cs:

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new HandleErrorAttribute { ExceptionType = typeof(DivideByZeroException), View = "DivideByZeroException", Order = 1 });
    filters.Add(new HandleErrorAttribute { View = "AllOtherExceptions", Order = 2 });
}
Run Code Online (Sandbox Code Playgroud)

到web.config我添加了:

<customErrors mode="On">
Run Code Online (Sandbox Code Playgroud)

然后创建了相应的视图,最后在其中一个动作中添加了DivideByZero-throw.

结果:呈现了视图AllOtherExceptions.

asp.net-mvc asp.net-mvc-3

6
推荐指数
2
解决办法
4975
查看次数

标签 统计

asp.net-mvc ×1

asp.net-mvc-3 ×1