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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With