HttpCookie ck = Request.Cookies["cktest"];
if (ck == null)
{
ck = new HttpCookie("cktest");
ck.Value = "123";

ck.Expires = DateTime.Now.AddSeconds(20);//20秒的有效期
Response.Cookies.Add(ck);
Response.Write("new ck");
}
else
{
Response.Write(ck.Value.ToString());
}

//在一个Cookie中储存多个信息
/**//*
HttpCookie cookie = new HttpCookie("cktest");
cookie.Values.Add("v1","1");
cookie.Values.Add("v2","2");
cookie.Values.Add("v3","3");
Response.AppendCookie(cookie);


HttpCookie cookies = Request.Cookies["cktest"];
string value1 = cookies.Values["v1"];
string value2 = cookies.Values["v2"];

Response.Write(value1 + value2);

*/