Introducing the Filter Types
The MVC Framework supports five different types of filters. Each allows you to introduce logic at different points during request processing. The filter types are described in Table 18-2.
Filter Type
|
Interface
|
Default Implementation
|
Description
|
---|---|---|---|
Authentication
|
IAuthenticationFilter
|
N/A
|
Runs first, before any other filters or the action method, but can be run again after the authorization filters
|
Authorization
|
IAuthorizationFilter
|
AuthorizeAttribute
|
Runs second, after authentication, but before any other filters or the action method
|
Action
|
IActionFilter
|
ActionFilterAttribute
|
Runs before and after the action method
|
Result
|
IResultFilter
|
ActionFilterAttribute
|
Runs before and after the action result is executed
|
Exception
|
IExceptionFilter
|
HandleErrorAttribute
|
Runs only if another filter, the action method, or the action result throws an exception
|
Before the MVC Framework invokes an action, it inspects the method definition to see if it has attributes that implement the interfaces listed in Table 18-2. If so, then at the appropriate point in the request handling process, the methods defined by these interfaces are invoked. The framework includes default attribute classes that implement the filter interfaces.
Tip |
MVC 5 introduces a new interface, IoverrideFilter,
|
No comments:
Post a Comment