Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 550
Marcos Lima Avatar asked Oct 22 '22 16:10

Marcos Lima


1 Answers

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

like image 164
thitemple Avatar answered Oct 28 '22 00:10

thitemple