按照什么顺序滤波器asp.net的MVC执行 [英] In what order are filters executed in asp.net mvc
问题描述
在MVC,我们可以装饰的操作方法与不同的过滤器,比如
In MVC we can decorate action methods with different filters like
[HttpPost]
[Authorize]
public ActionResult mymethod(){}
HttpPost
从 MethodSelectorAttribute
导出(可能是间接的)和授权
属性从 ActionFilterAttribute
继承。
HttpPost
derives from MethodSelectorAttribute
(probably indirectly) and the Authorize
attribute inherits from ActionFilterAttribute
.
我的问题是:在顺序它们在MVC请求管道执行?我试图去MVC源$ C $ C搜索,但未能找到相关code位。
My question is: in which order are they executed in the MVC request pipeline? I tried to go search in MVC source code but failed to find the relevant code bits.
推荐答案
过滤器运行下面的命令:
Filters run in the following order:
- 授权过滤器
- 动作过滤器
- 响应滤波器
- 异常过滤器
例如,授权过滤器首先运行和异常过滤器最后一次运行。在每个过滤器类型,订单值指定运行顺序。在每个过滤器类型和顺序,范围枚举值指定过滤器的顺序。该枚举定义了以下过滤器范围值(按顺序它们运行):
For example, authorization filters run first and exception filters run last. Within each filter type, the Order value specifies the run order. Within each filter type and order, the Scope enumeration value specifies the order for filters. This enumeration defines the following filter scope values (in the order in which they run):
- 首页
- 全球
- 控制器
- 动作
- 最后
这篇关于按照什么顺序滤波器asp.net的MVC执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!