我在 MVC 应用程序的 Controller 中使用了 2 个属性。 AttributeA 扩展 System.Web.Mvc.AuthorizeAttribute和 AttributeB 扩展 System.Web.Mvc.ActionFilterAttribute .我希望 AttributeB 始终首先运行。
我已经尝试了基于 this article 的所有可能的 Order 组合。 ,但 AttributeA 是 总是 在 AttributeB 之前运行。任何人都可以帮忙吗?
最佳答案
如果你看 System.Web.Mvc.ControllerActionInvoker.InvokeAction
使用反射器的方法,您将看到所有过滤器都实现了 IAuthorizationFilter在派生自 ActionFilterAttribute 的属性之前调用那是因为授权是在调用操作之前进行的。
关于asp.net-mvc - FilterAttribute 顺序不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1701546/