我在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.