11

I have two custom attributes in my asp.net mvc(C#) application.

[CustAttribute1()]
[CustAttribute2()]

When I use those attributes to my actions, which will get executed first?

[CustAttribute1()]
[CustAttribute2()]
public ActionResult Index()
{

Can I use more than one custom attributes for my actions? If so, in the above Action, which custom attribute will execute first?

1 Answer 1

16

Set the Order property.

[CustAttribute1(Order=2)]
[CustAttribute2(Order=1)]
public ActionResult Index() {
    return View();
}
Sign up to request clarification or add additional context in comments.

3 Comments

What about the attributes which are added in filters in FilterConfig (Mvc 5)
Without specifying the Order, does the order of appearance is the order of invocation?
It's true only for FilterAttribute

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.