According to this documentation for ASP.NET Filters filters run in the following order:
- Authorization filters
- Action filters
- Response filters
- Exception filters
The within each filter type there is a filter Order which specifies the run order.
Makes sense so far... but then it gets bizarre.
There is a further method of ordering within each filter type and order which is represented as an enumeration of the following values:
public enum FilterScope
{
First = 0,
Global = 10,
Controller = 20,
Action = 30,
Last = 100,
}
What bearing does Global, Controller and Action have within the run order for an action filter?
For example:
If I have two Action Filters, both with a run order of 1 and FilterScope
of Controller and Action respectively.
Other than ordering one in front of the other, what bearing does Controller
and Action
have on anything?
Further Bizarreness
According to this the FilterScope
provides third level ordering for filters. How is Controller
, Global
, or Action
an order for a filter that is in no way restricted for use on just a Controller
, Action
and not necessarily applied globally? It isn't descriptive of an order.
Also, if it does provide third level filtering, why is it restricted to just the 5 options?
FilterScope
defines where you use the filter: globally, on the whole controller or on some action. So the first one that will execute will be a global filter, then controller and then action – Rosenthalfilter type and order
, it would surely be overarching these. So it would be: Filter Scope, Filter Type, Filter Order. Not the other way around? – HeidiOrder
is for. Why would I want to set my filter to beOrder = 0
(first) andFilterScope = Last
. It doesn't make any sense. It doesn't restrict the usage of a filter, it just sets the ordering – HeidiScope
value - it's implicitly assigned based on usage. So I think this is basically tie-breaking rules since, at the same level, you're not allowed to assign the sameOrder
to multiple filters, but when considering global, controller and actions you may end up with 3 filters all (validly) with the sameOrder
. – Monseigneur