Cookie usage and precautions

Source: Internet
Author: User

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?

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.