简体   繁体   中英

Skip OnActionExecuted execution

I made an ActionFilterAttribute that has the OnActionExecuted method implemented. That means, it runs after the Action method. But, in certain condition, I want the OnActionExecuted to not be executed.

How do I, from the Action method, prevent the ActionFilter from being executed?

For now, I have made this:

On the Action method:

RouteData.Values.Add("CancelActionFilter", true);

And on the ActionFilter.OnActionExecuted():

if (filterContext.RouteData.Values["CancelActionFilter"] != null)
{
    return;
}

But I think that may exist a more elegant approach.

OnActionExecuted is called inside the InvokeActionMethodFilter method in the ControllerActionInvoker class.

Inside this method there's nothing to prevent the action of been executed. I think yours is a good solution.

Code of ControllerActionInvoker class

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