/////////////////////////////读取///////////////////////////////
//获得此cookie对象
HttpCookie cookie = Request.Cookies["demo"];
//检验Cookie是否已经存在
if (null == cookie) {
Response.Write("Cookie not found. <br><hr>");
}
else {
//显示Cookie的值
String strCookieValue = cookie.Value.ToString();
Response.Write("The " + strCookieName + " cookie contains: <b>"
+ strCookieValue + "</b><br><hr>");
}
/////////////////////////////写入///////////////////////////////
//创建一个新Cookie
HttpCookie cookie = new HttpCookie("demo");
//设定Cookie的值
cookie.Value = "value";
//设定cookie生命为1周,也就是7天
cookie.Expires = DateTime.Now.AddDays(7);
//添加Cookie
Response.Cookies.Add(cookie);