What is the use of Asp.Net MVC 2.0 Filter
This article will explain in detail what is the usage of Asp.Net MVC 2.0 Filter, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.
MVC 2.0 includes the following filters
1.Authorize
2.HandleError
3.RequireHttps
4.OutputCache
1. First of all, Authorize.
Authorize is mainly used to achieve user authorization and access.
[Authorize(Roles="Admins",Users="zx")]
publicActionResultDellUser(stringuserName)
{
returnView("about");
}
The above code indicates that the action DellUser can only be accessed by zx users under the role admins, and other users and roles are prohibited from accessing
2.HandleError
[HandleError(Order=1,ExceptionType=typeof(ArgumentException),View="Error")]
[HandleError(Order=2,ExceptionType=typeof(Exception))]
publicActionResultDellUser(stringuserName)
{
if(string.IsNullOrEmpty(userName))
{
thrownewArgumentException();
}
returnView("about");
}
HandleError is used as exception handling, where order indicates the order in which exceptions are handled, with lower numbers giving higher priority.
ExceptionType indicates the exception type
View indicates the page to which an exception occurred.
Asp.NetMVC2.0Filter What are the uses?
3.OutputCache
[OutputCache(Duration=60)]
publicActionResultDellUser(stringuserName)
{
returnView("about");
}
OutputCache is used to represent page caching. In the WEBFORM era, this attribute can be set directly in ASP.NET pages, and the attribute can be marked directly on ACTION in MVC.
4.RequireHttps
[RequireHttps]
publicActionResultDellUser(stringuserName)
{
returnView("about");
}
RequireHttps means that the action DellUser can only be accessed using https protocol, and other protocols cannot be used.
About "Asp.Net MVC 2.0 Filter what usage" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.