1

I'm currently investigating the possibility to use custom attributes derived from ActionFilterAttribute. I want to accomplish a couple of things with a couple of attributes. The thing is I want to make sure one of the attributes comes into play first, and not in any random sequence.

Example:

public class Feature1Attrubute : ActionFilterAttribute
{
    /* ... */
}

public class Feature2Attrubute : ActionFilterAttribute
{
    /* ... */
}

public class MyController : Controller
{
    [Feature1, Feature2]
    public ActionResult MyAction ()
    {
        /* ... */
    }
}

Is it so that attributes are applied in the sequence they mentioned in the method decoration?

If not, is there a way to define a particular sequence for a group of [custom] attributes?

1 Answer 1

5

The base class ActionFilterAttribute has a property called Order. That's what you're looking for.

public class MyController : Controller
{
    [Feature1(Order = 1), Feature2(Order = 2)]
    public ActionResult MyAction ()
    {
        /* ... */
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Right, I remember something of the kind was mentioned in some article, without details however. Thanks. Will give it a try.

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.