Today, we are going to learn about the filters in ASP.NET MVC. We will be dividing this article as follows:
  • What are filters
  • Types of filters
  • Action Filters

What are the filters

Sometimes we would like to perform certain action before or after a particular operation, or some times we need a pre or post action behaviors from action, for achieving this functionality ASP.NET MVC provides a feature called Filters.

Types of filters

ASP.NET MVC supports following types of filters:
  1. Action Filters
  2. Authorization Filters
  3. Result Filters
  4. Exception Filters
  5. Action Filters:
Action filters are used to implement the logic that get executed before or after a controller action executes.
Authorization Filters
It is used to implement authorization and authentication for action filters
Result Filters
Result filters contains logic that gets executed before or after a view result gets executed. E.g. if you want to change view before its get render to browser.
Exception Filters
Exception filters are used to handle error, caused by either controller action or controller action results, we can also use it for logging the exceptions.

Action Filter in ASP.NET MVC

Action Filters can be applied to either controller action or controller itself, with the help of action filter we can change the way, the action or controller gets executed.
MVC provides following action filters
So these are the action filters, hopefully I was able to satisfy you, more will come with the next article on custom filters.
Thanks!
Happy Coding.
Read more articles on ASP.NET: