すべての例外を処理してログに記録するために、グローバル アクション フィルターを使用しています。
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.ExceptionHandled
true に設定されます。OnException
ElmahHandleErrorAttribute