Action Filter In ASP.NET

Action filters are used to implement the logic that gets executed before or after an action method executes. Action filter attributes can be applied to a controller or to an individual action method. To create an action filter IActionFilter is used.
 
IActionFilter is an interface that provides two methods,
  1.  OnActionExecuting
  2. OnActionExecuted
These methods will be executed after or before action is executed.
 
The ASP.NET MVC Framework provides the following action filters.
  1. OutputCache
  2. HandleError
  3. Authorize
OutputCache

This filter caches the output of action for a certain duration. It makes controller's action output cacheable for the specified time. Output cache has one important feature that it supports an action filter that can be called all the time. Even when the action is marked with a cache attribute.
 
HandleError
 
When a controller action is executed, this action filter handles errors raised. If any error occurs during the action execution, it will find a view named Error in the Views folder and render that page to the user. The HandleError attribute is generally added in the Global.asax.cs file and registered in the Application_Start event.
 
Authorize
 
It is used for filtering the authorized user to access the resource. After registering on the system or application, registered user logs in to the application, it displays a particular page. It allows only authorized users to log into the system or application. 


Next Recommended Reading Action Method Parameters In ASP.NET MVC