Skip OnAction Completed

I created an ActionFilterAttribute that has an OnActionExecuted method. This means that it starts after the Action method. But under certain conditions, I want OnActionExecuted not to execute.

How can I, from the Action method, prevent the execution of an ActionFilter?

Currently I have done this:

In the Action method:

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

And on ActionFilter.OnActionExecuted ():

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

But I think there may be a more elegant approach.

+4
source share
1 answer

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

There is nothing inside this method to prevent action. I think yours is a good decision.

Class code ControlctionActionInvoker

+3
source

All Articles