Session viewstate cookie usage

Source: Internet
Author: User

Session viewstate cookie

Session
Session. Add ("variable", "value ");// Save
Session ["variable"] = value;// Save
STR = session ["variable"];// Obtain

Viewstate
Viewstate ["variable"] = value;// Save
Value = viewstate ["variable"];// Obtain

Cookie
// Create an httpcookie object
Httpcookie cookie = new httpcookie (namefield. Text );
// Set this cookie value
Cookie. value = valuefield. text;
// Set the cookie lifecycle, which is defined as an hour
Datetime dtnow = datetime. now;
Timespan tsminute = new timespan (0, 1, 0, 0 );
Cookie. expires = dtnow + tsminute;
Cookie ["name"] = "Wang Tian ";
Cookie ["gender"] = "male ";
Cookie ["Age"] = "26 ";

Response. Cookies. Add (cookie );// Add this cookie

Httpcookie cookie = request. Cookies ["Cookie name"]; // Read

Of course the aboveCodeThe generated cookie is a bit monotonous in the content. In fact, for cookies with rich content, there are many other attributes that can be used to make full use of these attributes. The following table lists common attributes of cookies:

Attribute description
Domain: Set/obtain the domain name to which the cookie belongs. Once this attribute is set, only the Web server of this domain name can access this cookie. It can be set to "ccw.com.cn"
Path: Specifies the path to which the cookie belongs. If so, the Web Page Accessing the cookie is restricted to this path. Web pages in other paths cannot be accessed.
Secure sets/gets an identifier to indicate whether the cookie can be securely transmitted to the client browser using the HTTP protocol.
Haskeys indicates whether the cookie is composed of multiple strings.

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: info-contact@alibabacloud.com 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.