多值Cookie的写法

//多值Cookie的写法

//方式1:
Response.Cookies["userinfo1"]["name"].value="1";
Response.Cookies["userinfo1"]["last"].value="1";
Response.Cookies["userinfo1"].Expires=DateTime.MaxValue; 

//方式2:
HttpCookie cookie = new HttpCookie("userinfo1");
cookie.Values["name"]="mike";
cookie.Values["last"]="a";
cookie.Expires=DateTime.MaxValue; 
//cookie.Expires = System.DateTime.Now.AddDays(1);
Response.Cookies.Add(cookie);


//多值Cookie的读取
If ( Request.Cookies["userInfo1"]!=null )
{
  string name=Request.Cookies["userInfo1"]["name"];
  string last=Request.Cookies["userInfo1"]["last"]; 
}

你可能感兴趣的:(乱七八糟)