I'm using a global action filter to handle and log all exceptions.
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new ElmahHandleErrorAttribute());
filters.Add(new HandleErrorAttribute());
}
This is how the global action filter ElmahHandleErrorAttribute
is defined - it overrides the OnException
method.
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
}
}
...
}
I don't understand why the value of context.ExceptionHandled
is true when the OnException
method executes.
How is this exception getting handled?
-EDIT-
I have a customErrors
section in the Web.Config
. I have an ErrorController
class, and actions called General
and Http404
.
<customErrors mode ="On" defaultRedirect="Error/General">
<error statusCode="404" redirect="Error/Http404"/>
</customErrors>
What I don't understand is, the controller action General
is not executed (breakpoint is never hit), but the value of ExceptionContext.ExceptionHandled
is set to true when the OnException
method of ElmahHandleErrorAttribute
starts executing.
context.ExceptionHandled
in your code, where is it? – Startlingif (!context.IsChildAction && !context.ExceptionHandled && (context.HttpContext.IsCustomErrorEnabled))
– ContractileOnException
method of the controller? – StartlingOnException
method of the MVCHandleErrorAttribute
filter. – Contractile