Filters
Filters in ASP.NET MVC enable you to run code before or after a particular stage in the execution pipeline. They can be configured globally, per controller, or per action. You can consider filters as interceptors.
There are different kinds of filters, and each filter is executed at a different stage in the pipeline. For example, action filters are executed when the action method is executed.
Let us use a simple example to see how an action filter (a type of filter) works.
We've created a simple controller, DateController, where we're just displaying the time. In this action method, we're using a predefined action filter by the name of ResponseCache, that caches the response for the duration specified in seconds. In the following code ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access