简体   繁体   中英

Does Controller.OnException get called before ExceptionFilter?

Trying to understand the MVC pipeline here:

It seems that the order is like so:

  1. AuthorizationFilters
  2. OnActionExecuting
  3. ActionExecutes
  4. OnActionExecuted
  5. OnResultExecuting
  6. Create the action result
  7. OnResultExecuted
  8. Write to response stream

When does the Controller.OnException run relative to the ExceptionFilterAttribute.OnException ?

It's probably documented somewhere, in the source at least, but I just ran 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 the Output Window shows:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM