Tuesday, July 16, 2019

ASP.NET MVC - Action Filters

Some time we want to perform logic either before as action method is called or after an action method runs.
To support this, ASP.NET MVC provides filters

1. Action Filters

  • OutputCache − Caches the output of a controller action for a specified amount of time.
  • HandleError − Handles errors raised when a controller action is executed.
  • Authorize − Enables you to restrict access to a particular user or role.


2. Types of Filters

The ASP.NET MVC framework supports four different types of filters −
  • Authorization Filters − Implements the IAuthorizationFilter attribute.
  • Action Filters − Implements the IActionFilter attribute.
  • Result Filters − Implements the IResultFilter attribute.
  • Exception Filters − Implements the IExceptionFilter attribute.
Filters are executed in the order listed above. For example, authorization filters are always executed before action filters and exception filters are always executed after every other type of filter.

No comments:

Post a Comment