すべての例外を処理してログに記録するために、グローバル アクション フィルターを使用しています。
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時に の値が true になる理由がわかりません。OnExceptionこの例外はどのように処理されますか?
-EDIT-
にcustomErrorsセクションがありWeb.Configます。私にはErrorControllerクラスがあり、アクションは and と呼ばGeneralれHttp404ます。
<customErrors mode ="On" defaultRedirect="Error/General">
<error statusCode="404" redirect="Error/Http404"/>
</customErrors>
私が理解していないのは、コントローラーのアクションGeneralは実行されません (ブレークポイントはヒットしません) が、メソッドの実行が開始されると、の値はExceptionContext.ExceptionHandledtrue に設定されます。OnExceptionElmahHandleErrorAttribute