I have two filters added to a WebAPI controller:
[FooFilter]
[BarFilter]
public IQueryable<SomeEntity> GetSomething()
{
...
Unfortunately, they are being executed in random order.
For the MVC stack, there’s the Order property where one could just do
[FooFilter(Order = 1)]
[BarFilter(Order = 2)]
public IQueryable<SomeEntity> GetSomething()
{
...
There’s an article on StrathWeb about adding Order support to WebAPI, which seems outdated and just won’t compile for me.
Do the C# wizards of SO have any advice on how to implement/stub the Order attribute for WebAPI?
The solution from the article works fine and compiles.
Just make sure you use the correct namespaces, since some of the classes have the same name under
System.Web.MvcandSystem.Web.Httpnamespaces.These are the fully qualified names you should be referencing:
Also, remember that once implemented, your filters need to start inheriting from
BaseActionFilterAttributeinstead of the originalActionFilterAttribute(that’s the only way you’d get thePositionproperty).