什么是全局过滤器的执行顺序MVC 4 [英] What is the execution order of global filters MVC 4

查看:506
本文介绍了什么是全局过滤器的执行顺序MVC 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的MVC应用4 2全球行动的过滤器,我已经在Filter.config文件中使用RegisterGlobalFilters注册。我需要他们以特定的顺序来执行。

I have 2 global action filters in my MVC 4 application, that I've registered in Filter.config file using RegisterGlobalFilters. I need them to be executed in a particular order.

我知道如何为特定的控制器指定的过滤器订单,但我怎么指定我的全局筛选顺序和范围是什么?它是在其注册的顺序?

I know how to specify order for Controller specific filters but how do I specify order and scope for my global filters? is it in the order in which they are registered?

推荐答案

由于没有答案已经thusfar已经给出关于如何指定在RegisterGlobalFilters全局过滤器的顺序,这是我的回答是:

As no answer has thusfar been given about how to specify the order of global filters in RegisterGlobalFilters, here's my answer:

您可以指定Add方法的顺序,通过传递第二个参数:

You can specify the order in the Add method, by passing in a second parameter:

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new HandleErrorAttribute(), 1);
    filters.Add(new LogFilter(), 2);
}

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

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