我正在使用全局操作过滤器来处理和记录所有异常。
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new ElmahHandleErrorAttribute());
filters.Add(new HandleErrorAttribute());
}
这就是全局操作过滤器ElmahHandleErrorAttribute的定义方式——它覆盖了OnException方法。
public class ElmahHandleErrorAttribute : System.Web.Mvc.HandleErrorAttribute
{
public override void OnException(ExceptionContext context)
{
//Is the exception handled already? context.ExceptionHandled seems to be true here
if (!context.IsChildAction && (context.HttpContext.IsCustomErrorEnabled))
{
//Do other stuff stuff
//Log to Elmah
}
}
...
}
我不明白为什么方法执行context.ExceptionHandled时的值为真。OnException如何处理此异常?
-编辑-
我customErrors在Web.Config. 我有一个ErrorController班级,以及名为Generaland的动作Http404。
<customErrors mode ="On" defaultRedirect="Error/General">
<error statusCode="404" redirect="Error/Http404"/>
</customErrors>
我不明白的是,控制器动作General没有执行(断点永远不会命中),但是当方法开始执行时,它的值ExceptionContext.ExceptionHandled设置为true 。OnExceptionElmahHandleErrorAttribute