ASP.NET MVC Action Filters
The MVC framework provides the filter attribute so that we can filter the user requests. We can apply it to an individual action or an entire controller. It completely modified the way in which an action is called.
The ASP.NET MVC Framework provides the following action filters.
OutputCache: it makes controller's action output cacheable for the specified time.
HandleError: It is used to handle error raised when a controller action executes.
Authorize: It allows only authorize user to access resources.
Here, we are implementing OutputCache that will cache the action method output for the specified time. The action code is given below:
It renders an index file that has the following code.
It produces the following output and cache that for 10 seconds. It will not change before 10 seconds even we refresh the web page again and again.
Now, we are applying authorize attribute to the action method, the code is given below.
This attribute will restrict unauthorized user access. The application redirects to the login page for authentication.