按照什么顺序滤波器asp.net的MVC执行 [英] In what order are filters executed in asp.net mvc

查看:229
本文介绍了按照什么顺序滤波器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:


  1. 授权过滤器

  2. 动作过滤器

  3. 响应滤波器

  4. 异常过滤器

例如,授权过滤器首先运行和异常过滤器最后一次运行。在每个过滤器类型,订单值指定运行顺序。在每个过滤器类型和顺序,范围枚举值指定过滤器的顺序。该枚举定义了以下过滤器范围值(按顺序它们运行):

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):


  1. 首页

  2. 全球

  3. 控制器

  4. 动作

  5. 最后

这篇关于按照什么顺序滤波器asp.net的MVC执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆