Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the order of execution when dealing with .NET MVC 2 Action Filters?

Say I have:

[Attribute1(Order=0)]  
public class Controller1  
{  
    [Attribute2]  
    [Attribute3]  
    public ActionResult Action1() { ... }  
}

The attributes get executed in the following order: 2, 3, 1

This makes sense because attributes 2 and 3 have an order of -1 and will be executed before attribute 1 which has an explicitly set order equal to 0.

Now, lets say I have:

[Attribute1]  
[Attribute2(Order=0)]  
public class Controller1  
{  
    [Attribute3]  
    public ActionResult Action1() { ... }  
}

The attributes get executed in the following order: 1, 2, 3

Why is it that attribute 2 in this case (which has an order equal to 0) is executed before attribute 3 (which has an order equal to -1)?

like image 964
user357933 Avatar asked Jun 03 '10 21:06

user357933


1 Answers

They should be executed in the order 1, 3, 2, just as you had proposed. And in fact, they execute in the correct order on my machine.

Can you provide the definitions of your three attributes? There might be something else in play here.

like image 181
Levi Avatar answered Sep 21 '22 12:09

Levi