Asp tutorial. net application cookie sessions server built-in object
The asp.net tutorial has many built-in objects, including application, response, request, cookie, sessions, cache, server, viewstate, and so on. Through these objects, You can provide some essential functions of the website, such as the absolute path of the file to be obtained, the number of online users, the total number of visitors to the website, and the online shop shopping box.
The cookie object uses the key/value pair method to record data. The statement mycookie. expires = datetime. now. addhours (1) specifies when the data in the cookie expires. In this case, it will expire after 1 hour. If no expiration time is specified, the website will immediately become invalid when it exits.
Write
The method of cookie value is as follows:
Httpcookie mycookie = new httpcookie ("userinfo ");
Mycookie. value = 2. tostring ();
Mycookie. expires = datetime. now. addhours (1); response. cookies. add (mycookie );
The method to retrieve the cookie value is as follows:
Httpcookie mycookie = request. cookies ["userinfo"];
Int num = convert. toint16 (mycookie.
Value
);
1 2 3 4