Question

I have two custom ActionFilters on an action.

In first of the actionfilters, I have an redirect performed if a condition is not met (classic authorization). And in another I have an redirect performed if another condition is not met (say role checking).

But I do not want to continue to the second actionFilter if the first one is not met. How to do this?

Was it helpful?

Solution

Setting the filterContext.Result property to any non-null value will stop execution of later filters. So if your first filter sets filterContext.Result = new RedirectResult(...), the second filter and action method will never be run. This is how the built-in [Authorization] filter works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top