Cookie usage is similar to session. A namevaluecollection type is found in the httpcookie class member, which is the icollection interface. This indicates that cookies support key-value queues and are used like session. Cookie and session are similar in terms of usage.
For example:
Add settings
Httpcookie cookie = new httpcookie ("test ");
Cookie. Values. Add ("name", "name1 ");
Cookie. Values. Add ("Age", "30 ");
Cookie. Values. Add ("sex", "boy ");
Cookie. Values. Add ("lastname", "Liu ");
Cookie. expires = datetime. Now. addyears (1 );
System. Web. httpcontext. Current. response. Cookies. Add (cookie );
System. Web. Security. formsauthentication. setauthcookie ("test", false );
Read:
Httpcookie coke = system. Web. httpcontext. Request. Cookies ["test"];
String name = coke ["name"];
String age = coke ["Age"];
String sex = coke ["sex"];
Session usage is similar.
However, the functions are different.
Session is stored on the server. However, the cookie is stored on the client. Specifically, it is stored in the currently logged-on user file directory under the Documents and Settings directory. Because it is stored on the user end, cookie is not suitable for storing important user information relative to session.
Cookie discovery has the following features:
For users who use cookies, it is best to first determine whether your IE has disabled this function:
For example:
If (request. browser. Cookies = true)
{
}
User deadline
Expires (TERM): Get or set the cookie end date and Time You can set it to an earlier date to automatically terminate or delete the cookie. if no date is set, the page will automatically delete the cookie.
The above is a bit of understanding about cookies, but there are still some small issues that do not know why?
1: How the cookie information is sent to the server. For a webpage request, the client will send the request address to the server through post GET header or other methods?