当前位置 : 主页 > 网络编程 > net编程 >

asp.net cookie

来源:互联网 收集:自由互联 发布时间:2023-10-08
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
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);

*/
上一篇:自动build服务器 CruiseControl.NET
下一篇:没有了
网友评论