I found one way to do this by “slightly changing” with the order, inheritance, and AttributeUsage parameter
First define your ActionFilter for the controller
[AttributeUsage(AttributeTargets.Class)] public class FilterController : ActionFilterAttribute { public FilterController() { this.Order = 2; } public override void OnActionExecuted(ActionExecutedContext filterContext) { if (!filterContext.HttpContext.Items.Contains("WeAlreadyWentThroughThis")) {
Then we inherit the class for your action attribute
[AttributeUsage(AttributeTargets.Method)] public class FilterAction : FilterController { public FilterAction() { this.Order = 1; } }
This is far from ideal, as you need to rely on HttpContext and two classes (although you can use namespaces to designate both classes to be the same). But you get a compiler-verified check of the attribute area for the class or action, and you will not forget the order parameter when entering the code.
source share