Web API Filters=>
Web API includes filters to add extra logic before or after action method executes. Filters can be used to provide cross-cutting features such as logging, exception handling, performance measurement, authentication and authorization.
Filters are actually attributes that can be applied on the Web API controller or one or more action methods. Every filter attribute class must implement IFilter interface included in System.Web.Http.Filters namespace. However, System.Web.Http.Filters includes other interfaces and classes that can be used to create filter for specific purpose.
Filter Type | Interface | Class | Description |
---|---|---|---|
Simple Filter | IFilter | - | Defines the methods that are used in a filter |
Action Filter | IActionFilter | ActionFilterAttribute | Used to add extra logic before or after action methods execute. |
Authentication Filter | IAuthenticationFilter | - | Used to force users or clients to be authenticated before action methods execute. |
Authorization Filter | IAuthorizationFilter | AuthorizationFilterAttribute | Used to restrict access to action methods to specific users or groups. |
Exception Filter | IExceptionFilter | ExceptionFilterAttribute | Used to handle all unhandled exception in Web API. |
Override Filter | IOverrideFilter | - | Used to customize the behaviour of other filter for individual action method. |