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.