I have 2 action filter:
[Auth]
[Check]
public ActionResult Home()
{
//...
}
I need set CheckAttr first work and break AuthAttr.
I do not remember how to do it. Please help me.
example:
request to action Home -> first work Auth filter and logic I need redirect to another action
You could short-circuit the entire execution by setting the
Resultproperty of thefilterContext:In this example I have returned a JsonResult but you could return any ActionResult you like: ViewResult, PartialViewResult, RedirectToRouteResult, …
Once you assign the Result property no more filters will be executed for this context. The action execution itself will be short-circuited as well.
Also bear in mind that if your action filters are deriving from the same type there are no guarantees in which order they will be executed unless you manually assign the
Orderproperty on each of them. Of course if they are of different types such asIAuthorizationFilterorIActionFilter, it is obvious that authorization filters will run before any action filters. That’s by design.If on the other hand you are only attempting to prevent other action filters from executing but the action itself should execute, I am afraid that there’s no way to achieve that and you will have to rethink your design of those filters.