A global filter applies across an application's eligible endpoints without repeating attributes on controllers, Razor Pages, actions, or handlers. Action filters affect action endpoints; page filters affect Razor Page endpoints. section 30.6
Configure global filters through MVC options in Program.cs:
- Use opts.Filters.Add<T>() for a filter type. section 30.6
- Use AddService<T>() when the filter is also registered as a service. section 30.6
- Use the nongeneric Add method to register a specific filter object. section 30.6
- Expect global filters before controller- or page-model filters, followed by action- or handler-level filters. section 30.7
- Implement IOrderedFilter when sequencing matters; lower Order values run earlier, and negative values can precede default global filters. section 30.7
Apply HTTPS enforcement globally
Register `HttpsOnlyAttribute` with `builder.Services.Configure<MvcOptions>(opts => opts.Filters.Add<HttpsOnlyAttribute>())`, remove `[HttpsOnly]` from `HomeController`, restart the application, and request `http://localhost:5000`. The HTTPS-only policy still applies, and an authorization filter can short-circuit the pipeline. section 30.6
