我正在使用全局操作篩選器來處理和記錄所有異常。ExceptionContext.ExceptionHandled更改爲true。在哪裏處理異常?
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
方法執行時。 這個異常是如何處理的?
CNC中 我在Web.Config
一個customErrors
部分。我有一個ErrorController
課程,以及名爲General
和Http404
的操作。
<customErrors mode ="On" defaultRedirect="Error/General">
<error statusCode="404" redirect="Error/Http404"/>
</customErrors>
我不明白的是,不執行控制器動作General
(斷點從不打),但ExceptionContext.ExceptionHandled
值時的ElmahHandleErrorAttribute
開始的OnException
方法執行設置爲true。
我在代碼中看不到'context.ExceptionHandled',它在哪裏? – gdoron
@gdoron我刪除了關於context.ExceptionHandled的檢查。它早先包含在聲明中:'if(!context.IsChildAction &&!context.ExceptionHandled &&(context.HttpContext.IsCustomErrorEnabled))' – escist
您是否覆蓋了控制器的'OnException'方法? – gdoron