string strCookie=""; //创建一个名为user HttpCookie userCookie=new HttpCookie("user"); //value给单个Cookie值赋值 userCookie.Value="nihao"; Response.Cookie.Add(userCookie); //取值 HttpCookie userCookie=Request.Cookie["user"]; strCookie=userCookie.Value; //在一个Cookie中储存多个信息,那也没有问题 //values是获取单个cookie对象键值对的集合 HttpCookie userCookie=new HttpCookie("user"); userCookie.values.Add("nihao",txtName.value); userCookie.values.Add("nihao2",txtName2.value); Response.Cookie.Add(userCookie); //取值 HttpCookie userCookie=Request.Cookie["user"]; cookie1=userCookie.Values["nihao"]; cookie2=userCookie.Values["nihao"];
时间: 2024-09-29 07:52:20