.net读取cookie中的值

2024-12-12 18:58:37
推荐回答(2个)
回答1:

你好:
写入方法:
HttpCookie cookie = new HttpCookie("id");
cookie.Value=cookieValue;
cookie.Expires = DateTime.Now+new TimeSpan(0,1,0,0));
Response.Cookies.Add(cookie);
读取方法:
HttpCookie cookie = Request.Cookies["id"];
if(null == cookie)
{
Label1.Text = "";
}
else
{
Label1.Text = cookie.Value;
}

回答2:

if (Request.Cookies["id"]!=null)
Label1.Text=Request.Cookies["id"].Value;