Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of Asp.Net MVC 2.0 Filter

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report