views:

151

answers:

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?

+5  A: 

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 ()
    {
        /* ... */
    }
}
çağdaş
Right, I remember something of the kind was mentioned in some article, without details however. Thanks. Will give it a try.
User