ASP.NET MVC filter study notes

1, wherein two filters
1, he is a property, the controller can refer to the Action class and method. FIG example the
 
This action of the controller and method are cited filter, this filter is used for authorization
 
2, features inherited from FilterAttribute
So long as the inherited FilterAttribute, you can implement a custom filter
 
Typical filter 2, MVC frame
Authorize Authorization filter
Error processing filter HandlerError
OutputCache filter output buffer
 
1, the filter Authorization
A total of three uses
 
The first use = "unauthorized access based on the user, is added directly in the process of the controller and Action Authorize characteristics, do not set any property characteristics, the following code as an example, the user can log in only authorized to access the controller
 
 
The second method = "based on user authorization
The third method = "role-based authorization
 
 
Roles role authorization is used to assign an initial value of the property characteristics, a plurality of characters separated by a comma, the user authorization is similar to the same
 
After the verification is not passed, to automatically jump to the login page
 
2, caching filter
 
It is used to output the page cache
 
 
 
3, exception filter
Do not write to try catch in the controller.
 
 
 
 
 
 
 
3, MVC custom filter frame
 
 
 

Guess you like

Origin www.cnblogs.com/schangxiang/p/11286372.html