ASP.NET MVC 框架包括几个 Action 过滤器:
- OutputCache – 此操作过滤器将 Controller 操作的输出缓存一段指定的时间。
- HandleError – 此操作过滤器处理 Controller 操作执行时引发的错误。
- 授权 – 此操作过滤器使您能够限制对特定用户或角色的访问。
此外,在 MVC 中有一种过滤器称为“授权过滤器”。
我很困惑 [Authorize] 属性是 Action 过滤器还是 Authorization 过滤器?什么时候执行?
最佳答案
What is the difference between Authorize Action filter and Authorization filter?
没有。
该文档显然不正确(如果您在目录中注明,它是针对 MVC 的版本 1 和 2,因此它也已过时)。
AuthorizeAttribute
继承了IAuthorizationFilter
,所以它实际上是一个授权过滤器,而不是一个 Action 过滤器。 MVC 中没有授权操作过滤器。
请注意,对于 MVC 3 到 MVC 5,您应该引用最新的 Filtering in ASP.NET MVC将来的文档。
And when will it be executed ?
根据 MSDN :
Filters run in the following order:
- Authorization filters
- Action filters
- Response filters
- Exception filters
关于c# - Authorize Action 过滤器和 Authorization 过滤器有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38029094/