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.
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.
I have created a simple controller, DateController
, where I am just displaying the time. In this action
method, I am using a predefined action filter by the name of ResponseCache
, that caches the response for the duration specified in seconds. In the following code snippet, we have mentioned the duration as 600 seconds. ...
Get ASP.NET Core: Cloud-ready, Enterprise Web Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.