December 2019
Intermediate to advanced
510 pages
11h 33m
English
As we mentioned previously, filters can have three different scopes: global, controller, and action. In the first case, the filter is applied globally in the Startup class. In the other two cases, the filter is used in the form of an attribute and is usually applied to the controller class definition or the action method definition. Let's take a closer look at these different approaches. The application of a filter in the Startup class means that the filter covers all the routes in the MVC pipeline, as follows:
public class Startup { ... public void ConfigureServices(IServiceCollection services) { services .AddControllers(config => config.Filters.Add(new CustomFilter())); } ... }
In this case, CustomFilter has a global ...