What is the execution order of MVC 4 global filters

I have two global action filters in my MVC 4 application that I registered in the Filter.config file with RegisterGlobalFilters. I need them to be executed in a specific order.

I know how to specify the order for specific filters for the controller, but how to specify the order and scope of global filters? is it in the order in which they are registered?

+4
source share
2 answers

Since no answer was given on how to specify the order of global filters in RegisterGlobalFilters, here is my answer:

You can specify the order in the add method by passing the second parameter:

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

In this MSDN article, scroll down to the Filter Order section. There are Order and Scope properties that allow you to control the execution order.

+4
source

Source: https://habr.com/ru/post/1496837/


All Articles