. NET add cookies in 4 ways

Source: Internet
Author: User
Tags ole tostring

  This article mainly introduces 4 ways to add cookies to. NET, and friends who need it can refer to the

The code is as follows://The first method of adding cookies         HttpCookie MyCookie = new HttpCookie ("Userrole");         mycookie.values["a"] = "a";         mycookie.values[""] = "B";         myCookie.Expires.AddDays (1);         RESPONSE.COOKIES.ADD (MyCookie);        //response.appendcookie (MyCookie); This can also be added        //The first way to get cookie method         Response.Write (request.cookies["Userrole"). Values["a"]. ToString ());          //Second Add Cookie method         HttpCookie MyCookie = new HttpCookie ("Userr Ole ");         mycookie.values["a"] = "a";         mycookie.values["B"] = "B";         myCookie.Expires.AddDays (1);         RESPONSE.COOKIES.ADD (MyCookie);        //second Read Cookie method         HttpCookie cookie = Request.cookies["Userrole"];         Response.Write (cookies). Values["a"]. ToString ());         Response.Write (cookies). Values["B"]. ToString ());          //third method of adding cookies         HttpCookie MyCookie = new HttpCookie ("Userr Ole ");         Mycookie.value = "a";         RESPONSE.COOKIES.ADD (MyCookie);        //Third read Cookie method         Response.Write (request.cookies["Userrole"). Value);          //Fourth Add Cookie method         HTTPCONTEXT.CURRENT.RESPONSE.COOKIES.ADD ( New HttpCookie ("Userrole", "Super admin"));         response.cookies["Userrole"]. Value = "Super Administrator";         HttpCookie cookie = request.cookies["Userrole"];         Response.Write (cookies). Value);        //Third way to read cookies         Response.Write (request.cookies["Userrole"]. Value);

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.