HttpCookie

 

我们利用

 HttpCookie UserCookie = new HttpCookie("userName");
 UserCookie["name"]=dr["user"].ToString();

UserCookie.Expires=DateTime.Now.AddDays(1);//这里设置要保存多长时间.
 Response.Cookies.Add(UserCookie);
 

读取的时候
HttpCookie cookie=Request.Cookies["userName"];
string name=cookie.Values["name"];


清除cookie

 

HttpCookie cookie=Request.Cookies["userName"];
   if(cookie!=null)
   {
    cookie.Expires=DateTime.Now.AddDays(-2);   
    Response.Cookies.Set(cookie);
   }

 

posted @ 2009-11-21 15:01  Daniel_Lu  阅读(219)  评论(0编辑  收藏  举报