Use of cookies

Source: Internet
Author: User

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.web.ui.webcontrols;public partial class cookie:system.web.ui.page{protected void Page_Load (object sender, Eve Ntargs e) {}//create cookie protected void Button1_Click (object sender, EventArgs e) {HttpCookie Cooki        E = new HttpCookie ("MyCookie");        DateTime Dt=datetime.now; TimeSpan ts=new TimeSpan (0,0,1,0,0);//expiry time set to 1 minutes//Set expiration time Cookie.expires = dt.        ADD (TS);        COOKIE.VALUES.ADD ("name", "Yys");        COOKIE.VALUES.ADD ("Age", "24");            Response.appendcookie (Cookie);        }//Read protected void Button2_Click (object sender, EventArgs e) {if (request.cookies["MyCookie"]!=null) {Response.Write (request.cookies["MyCookie").                            Value); }}//Modify protected void Button3_Click (object sender, EventArgs e) {//Get the cookie object of the client HttpCookie COK = ReQuest.        cookies["MyCookie"]; if (cok!=null) {cok.            values["name"] = "Abner"; Cok.            Values.set ("Age", "20"); Add new content to the cookie, COK.            Values.set ("Sex", "male");                    Response.appendcookie (COK); Response.Write (request.cookies["MyCookie").                    Value); }}//delete protected void Button4_Click (object sender, EventArgs e) {HttpCookie co=request.cookies["MyCo        Okie "]; Co. Values.remove ("Sex");//Key-value pair Response.Write (request.cookies["MyCookie") with the key "sex" removed.        Value);        TimeSpan ts = new TimeSpan ( -1,0,0,0); Co. Expires = DATETIME.NOW.ADD (TS);//delete the entire cookie, just set the expiration time to now}}

  

Use of cookies

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.