ASP.Net MVC ActionFilterAttributes全局与本地排序 [英] ASP.Net MVC ActionFilterAttributes ordering Global vs Local

查看:204
本文介绍了ASP.Net MVC ActionFilterAttributes全局与本地排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有执行ActionFilterAttribute属性的命令.我猜本地的(在Controller的Action上定义的ActionFilterAttribute)按在Action上定义的顺序执行.

I was wondering if there was an order to the execution of ActionFilterAttribute attributes. I am guessing the local ones (an ActionFilterAttribute defined on the Action of a Controller) are executing in the order they are defined on the Action.

但是,是否在全局过滤器之前先应用全局过滤器,反之亦然?另外,如果有一个已定义的顺序,而不仅是任意顺序,那么在Mvc的各个版本中是否一致?

However does any one no whether Global filters are applied before local ones or vice versa? Also if there is a defined order and not just arbitary is it consistent across version of Mvc?

先谢谢了 汤姆

推荐答案

在每种过滤器类型中,顺序"值指定运行顺序.在每种过滤器类型和顺序中,范围"枚举值指定过滤器的顺序.此枚举定义了以下过滤器作用域值(按它们运行的​​顺序):

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. 最后
  1. First
  2. Global
  3. Controller
  4. Action
  5. Last

同样,你的假设

我猜本地(在Controller的Action上定义的ActionFilterAttribute)按在Action上定义的顺序执行

I am guessing the local ones (an ActionFilterAttribute defined on the Action of a Controller) are executing in the order they are defined on the Action

不正确,没有定义顺序/范围的过滤器没有定义的顺序

Is incorrect, there is no defined order for filters with no order/scope defined

具有相同类型,顺序和范围的过滤器的执行顺序未定义.

The execution order of filters that have the same type, order, and scope is undefined.

如果您关心它们的执行顺序,则应该使用

If you care about the order they are executed then you should specify this using the Order property.

这篇关于ASP.Net MVC ActionFilterAttributes全局与本地排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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