Exercise 2: Creating a Global Dynamic Filter
In this exercise, you will learn how to create a global dynamic filter that will get executed or not depending on the context. This means that you could set any filter as global, but use it only for the controllers or actions that satisfy a certain condition. For that purpose you will implement GetFilters method in your custom filter provider to add your own logic behind the filter retrieval.
Task 1 – Creating a Filter Provider
In this task, you learn how custom Filter Providers manage the global behavior of any MVC Filter. You will create a custom Filter Provider that stores the controller actions to log and applies the filter when an action is in the list.
Make ActionLogFilterProvider implement the interface IFilterProvider.
public class ActionLogFilterProvider : IFilterProvider
Public Class ActionLogFilterProvider Implements IFilterProvider
Task 2 – Registering a Global Filter
In this task, you will register a custom filter provider as global in the Global.asax.[cs|vb].
Task 3 – Running the Application
In this task, you will check that the controllers added to the filter provider list are actually performing the log.