1.创建名为 userid
的 cookie
HttpCookie cookie = new
HttpCookie("userid"); //设置cookie的名称
cookie.Value
= ((Maticsoft.Model.Personal)Session["person"]).userID.ToString();
//为cookie赋值
cookie.Expires
= DateTime.Now.AddDays(7); //设置cookie过期时间
Response.Cookies.Add(cookie); //保存cookie
2.清除cookie
HttpCookie cookie = Request.Cookies["userid"];
if (cookie
!= null && int.Parse(cookie.Value)
> 3)
{
HttpCookie
cookieNew = new HttpCookie("userid");
cookie.Expires
= DateTime.Now.AddDays(-1);
Response.Cookies.Add(cookieNew);
}
注意:
userid就是要清除的cookie名
3.接受cookie
if(Request.Cookies["userName"]
!= null)
{
textbox1.visible=false;
}