Web ---> Cookie and Session, web --- cookie
1. cookie
1. Cookies exist in the process memory of the client (browser) and on the hard disk of the machine on which the client is located.
2. Cookies can only store a small amount of text, about 4 kb
3. Cookies cannot be shared between different browsers.
3. Demonstration of cookie object Creation
// 3.0 instantiate the cookie object
HttpCookie cookie = new HttpCookie ("uid", uid );
// Tell the browser to send the cookie to the server only when the page in the specified path is requested. If no cookie is specified, the default value is/
Cookie. Path = "/P01cookiedemo /";
// If the Expires parameter is set, the browser is notified to store the cookie to the hard disk,
Cookie. Expires = DateTime. Now. AddDays (3 );
// Set Domain to tell the browser that the cookie is sent to the server only when a page under www.c11.com is requested
Cookie. Domain = "www.c11.com ";
// 4.0 Add the cookie to the response header and send it back to the browser for saving,
Response. Cookies. Add (cookie );
4. Get the cookie value that the browser sends to the server through the request header. uid: the cookie key, which can be defined by the programmer.
If (Request. Cookies ["uid"]! = Null)
{
Request. Cookies ["uid"]. Value;
}
5. How to clear the cookie code:
HttpCookie cookie = Request. Cookies ["uid"];
Cookie. Expires = DateTime. Now. AddYears (-1 );
Cookie. Path = "/P01cookiedemo /";
Response. Cookies. Add (cookie );
5. Single Sign-on
2. GMT, UTC time, zero time zone, East District + hour West District:-hour
In linux, the default time is UTC.
3. Session
1. There are servers and website processes in memory
2. When the session is set for the first time, a session object will be instantiated in the session pool, with the value of asp.net _ sessionid as the key, and the key will be in the form of a cookie.
Save to client memory
3. The session scope only exists in the session of the current browser. When the browser is closed, the sessionid will be lost, but the session object on the server will be recycled 20 minutes later.
Clear Session: context. Session ["name"] = null;
Context. Session. Abandon ();
4. Add <sessionState timeout = "5" cookieless = "true"> </sessionState> under the <system. web> node in web. config to manually modify session settings
Note:
After the aspx compilation is complete, the interface IRequiresSessionState is automatically implemented, so you can directly use the session
However, for a general processing program, the programmer must manually implement the system. Web. SessionState. IRequiresSessionState interface to use the session object.
You can use
Set: <sessionState cookieless = "true"> </sessionState> to enable the url to pass sessionid to the server, but it is not recommended to use