What are filters in ASP.NET MVC/Web API? Types and use cases?
What are filters in ASP.NET MVC/Web API? Types and use cases?
Student
The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
In ASP.NET MVC/Web API, filters are attributes that allow you to execute custom logic before or after controller actions run. They are a core part of the request pipeline and are used for cross-cutting concerns like logging, authentication, exception handling, etc.
Types of Filters in ASP.NET MVC / Web API
1. Authorization Filter
Use Case:
Example:
2. Action Filter
Use Case:
Example:
Usage:
3. Result Filter
Use Case:
Example:
4. Exception Filter
Use Case:
Example:
5. Authentication Filter (Web API only)
Use Case:
Applying Filters
FilterConfig.csSummary