. NET simple manipulation of cookies

Source: Internet
Author: User

1 statement: HttpCookie mycookie= new HttpCookie ("test");

2 added: MyCookie.Values.Add ("Key1", "value1"),//key1 is the key name, value1 is the value

3 Expires: Mycookie.expires = DateTime.Now.AddDays (1);//Expires after one day. You can also set a negative value to make the cookie expire immediately.

4 Add to client: Response.appendcookie (newcookies);//Add with Response

5 Value:

5.1 instantiation: HttpCookie TestCookie = request.cookies["Test"];//use Request value, determine TestCookie is not empty, detection of a cookie named Test does not exist

5.2 Value: String cookiestr = testcookie.value;//Gets a single cookie value

String key1str = testcookie.values["Key1"]//gets the value of the key named Key1 for the cookie named test

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.