【发布时间】:2011-11-15 23:37:11
【问题描述】:
我在我的 MVC 应用程序中继承了 HandleErrorAttribute,因此我可以记录错误:
public class HandleAndLogErrorAttribute : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
base.OnException(filterContext);
if( filterContext.Exception != null )
{
// log here
}
}
}
我将其添加为全局过滤器:
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleAndLogErrorAttribute());
}
是否也可以为特定的异常类型指定自定义视图?例如:
if( filterContext.Exception is DivideByZeroException )
{
// how do i specify that the view should be DivideByZero?
}
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-3