Advantages and disadvantages of ASP. NET client Status Management

Source: Internet
Author: User
Tags set cookie

Generally, HTTP is a non-State service that does not store any user request information. Until NetScape began to use Cookies to store user request information, the Web application had a great development. Currently, ASP. NET programmers can save user request information in many ways.

The following describes several methods of client status management in ASP. NET.

ASP. NET provides Cookies, QueryStrings (URL), Hidden fields, View State and Control state (ASP. NET 2.0) to manage client requests.

I. Cookie

Cookie is stored in the computer as text and matched with name-value. The user stores the user information, such as the user name and user configuration. Although cookies can be encrypted and stored, it is not recommended to store user passwords in cookies. Second, the Cookie size is limited, so it is not suitable for storing large data.


1. Obtain the user ID

if (Request.Cookies["UserId"] != null) lbMessage.text = "Dear" + Request.Cookies["UserId"].Value + ", Welcome to our website!"; else lbMessage.text = "Guest,welcome to our website!";

2. Set Cookie



Easy to use


1. The client can disable cookies.

2. Cookies are loaded every time they are requested or sent, affecting transmission.

3. It is easy to break through and is not suitable for storing security information.

Ii. Hidden fields (Hidden Control)

Hidden field stores information at the page level. The difference from other user-standard controls is that the Hidden Field is not displayed on the page. When the page is submitted, the value in the Hidden Field will be sent to the server in the same way. Although ViewState can be used in ASP. NET 2.0, Hidden Fields can still be used to store non-critical information.

Currently, ASP. NET programmers can save user request information in many ways. The following describes several methods of Status Management in ASP. NET.

protected System.Web.UI.HtmlControls.HtmlInputHidden Hidden1; //to assign a value to Hidden field Hidden1.Value="Create hidden fields"; //to retrieve a value string str=Hidden1.Value;


1. Easy to use

2. A small amount of data can be stored.


Insecure, transmitted directly from the network in plaintext

3. View State)

Status view ViewSate, which can be used to store information for individual users. You can set the EnableViewState attribute to control the use of ViewState. The default value is True. ViewSate is transmitted every time a user request or server response occurs. Therefore, to reduce network bandwidth usage, you can set the value of EnableViewState to False when you do not need a status view. The storage of ViewSate in the page is Base64 transcoded, and the additional data volume is added. Therefore, you must note that you save a small number of ViewSate files.

// Add item to ViewState ViewState["myviewstate"] = myValue; //Reading items from ViewState Response.Write(ViewState["myviewstate"]);


Easy to operate


It can be used at the control level


Encrypted encoding increases the page size.

Increased price for Network Transmission

  1. Several methods for transferring page values using ASP. NET
  2. XML data processing in ASP. NET 2.0
  3. Analysis on the hybrid application of C ++ and J # in ASP. NET

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.