asp.net-mvc - FilterAttribute 顺序不起作用

标签 asp.net-mvc attributes

我在 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/

相关文章:

javascript - 如何从功能标签的页面源代码中获取值?

c# - 加密 URL 中的路由数据

c# - MVC 脚手架不加载模型或上下文

javascript - 在 razor foreach 语句中调用 JavaScript 函数

asp.net - AngularJS ASP .Net MVC 登录

javascript - JQuery 未在我的 Controller 上调用 HttpPost 方法。我该如何解决这个问题,或者可能出了什么问题?

css - 将 PDF 图标应用于链接 - 缓存更改扩展

php - 如何使用 Magento 的 ORM 在我的自定义表和 magento 的表之间进行内部连接?

jQuery attr 不起作用

python - 如何使用项目名称中有冒号的属性