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 common state management of ASP.NET?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what is the common state management of ASP.NET". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what the common state management of ASP.NET has.

The common state management solutions for ASP.NET are:

◆ View status View state

◆ Hidden Domain Hidden Fields

◆ Cookies

◆ Query string

◆ Application state

◆ Session state

◆ Profile

ASP.NET commonly used state management in which View state, hidden fields, cookies, and and query strings save values on the client in different ways. Application state, session state, and and profile store values in different forms on the server side.

View state (View state)

View state automatically saves the values of each element of the web page, as long as the control's EnableViewState=true. ViewState stores the value of an element in the form of key-value pairs. In asp.net, the value of view state is stored in the page in a hash in the form of a hidden field, similar to:

If you use View state to store data, the size of the data cannot exceed the value defined by page's MaxPageStateFieldLength.

◆ advantages: no server-side resources, because view state is saved in the page, so there is no need to borrow server-side resources preservation value problem. Easy to use, you only need to save the value of the element in the form of key-value pairs. In terms of security, because the values saved by view state are hashed and compressed, it is safer to use than Hidden Fields.

◆ disadvantages: performance problems, because view state saves values in Page, so every time the page is loaded, the values saved in view state will be loaded, resulting in performance loss.

Security problem, although the value saved by view state is hashed and compressed, it still exists in the form of hidden fields in the page and is still easy to be intercepted and used by hackers.

Hidden domain (Hidden Fields):

This is an ancient way for asp to store element values. Using Hidden Fields depends on how the page submits the data. You must submit through the Post method to get the value of Hidden Fields, and if you use the Get method of Http, the value of the Hidden element is invalid.

Another feature of Hidden Fields is that it stores the values of elements in clear text in Html code. You can easily look at the page's html source code to get the value of the hidden fields element.

◆ advantages: easy to use, a wide range of applications, almost all browsers and client devices support hidden fields this form.

◆ disadvantages: very insecure, can only store very simple data, such as string types, performance problems, using hidden fields like view state should be loaded every time the page is displayed.

Cookies

Cookies is also a form of storing data on the client side. Cookies can save data for a long time or temporarily, depending on the expiration time setting of cookies. The scope of Cookies is the entire web site, not a page, it depends on the browser to manage, if the client browser disables Cookies, then you cannot enable Cookies to save data on the client side. Cookies sends the data to the server along with the request of the page, and its value can be obtained through Request. Most browsers support Cookies to store 4m bytes of data, while browsers also have a limit on the number of Cookies machines can hold, generally allowing up to 20 Cookies to be generated per site.

Read the value of Cookies:

If (Request.Cookies ["UserSettings"]! = null) {string userSettings; if (Request.Cookies ["UserSettings"] ["Font"]! = null) {userSettings = Request.Cookies ["UserSettings"] ["Font"];}} write values to Cookies: Response.Cookies ["UserSettings"] ["Font"] = "Arial"; Response.Cookies ["UserSettings"] ["Color"] = "Blue"; Response.Cookies ["UserSettings"]. Expires = DateTime.Now.AddDays (1D)

Advantages of ◆: expiration time can be configured, server-side resources are not required, it is easy to use, and persistent data can be maintained.

◆ disadvantages: size limit, most browsers support 4m bytes. Due to user configuration restrictions, if the browser disables Cookies, then this feature cannot be used, which is a potential security hazard. Because Cookies is stored in the client machine in the form of a text file, although the content of Cookies is hashed, it can still be obtained and used by people.

Query string

The query string is to add some parameters to the URL of the page to pass values between pages in this form. It provides a very convenient way to pass values on the page.

Advantages of ◆:

Simple and convenient, widely used

◆ disadvantages: extremely insecure, it is necessary to use URLEncode and URLDecode to deal with strings to enhance security. The size is limited, and some browsers or client devices only support URL strings of 2083 in length.

Application State

Asp.net allows you to store values as Application state-it is an instance of the HttpApplicationState class. Application state provides a global storage method that can be accessed by every page of a web application. Like Session State, Application state stores values in the form of key-value pairs.

◆ advantages: global scope

◆ disadvantages: global scope, server resource consumption, vulnerability, because Application State is stored in memory, it will be lost when the application is stopped or restarted. Poor scalability and cannot be shared among multiple servers or processors.

Session State

Session State is somewhat similar to Application state, but it works in browser sessions. Different users will have different session sessions if they use your application. Session state also stores data in the form of key / value pairs.

Advantages of ◆: easy to use and long-lasting data, because the Session provided by asp.net overcomes the shortcomings of the original asp process dependence, and the Session can be saved in the database, so the data of session will not be lost. There is no need for Cookies support, which is also a big improvement of asp.net, where client-side Session information can be stored in Cookieless in ASP.NET.

◆ disadvantage: because the Session variable is stored on the server side, it takes up server-side resources.

Profile

Storing data in the form of Profile is a new feature provided by asp.net2.0. It stores the information in the database, so the information is not lost.

Advantages of ◆: data persistence, extensibility

Disadvantages of ◆: because profile stores data in the database, it has the following characteristics, which requires manual maintenance of data, and its performance is slightly poor.

Thank you for your reading, the above is the content of "what is the common state management of ASP.NET". After the study of this article, I believe you have a deeper understanding of what the common state management of ASP.NET has, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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