Is Controller.OnException thrown before an ExceptionFilter?

Trying to understand the MVC pipeline here:

It seems that the order looks like this:

  • AuthorizationFilters
  • OnActionExecuting
  • Actionexecutes
  • OnActionExecuted
  • Onresultexecuting
  • Create an action result
  • Onresultexecuted
  • Writing to the response stream

When is a Controller.OnException thrown regarding an ExceptionFilterAttribute.OnException ?

+4
source share
1 answer

It was probably recorded somewhere, at least in the source, but I just did this little experiment:

// in MyHandleErrorAttribute, globally configured
public override void OnException(ExceptionContext filterContext)
{
    Debug.Print("HandleErrorAttribute.OnException 1");
    base.OnException(filterContext);
    Debug.Print("HandleErrorAttribute.OnException 2");
}

...

// in HomeController
protected override void OnException(ExceptionContext filterContext)
{
    Debug.Print("Controller OnException 1");
    base.OnException(filterContext);
    Debug.Print("Controller OnException 2");
}

and in the output window:

HandleErrorAttribute.OnException 1
HandleErrorAttribute.OnException 2
OnException 1
OnException 2

+3

Source: https://habr.com/ru/post/1584764/


All Articles