#中cookies的读取写入操作如下:
/读取///
//获得此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);
对 cookies 操作!
最新推荐文章于 2024-04-18 07:00:00 发布