您的位置:首页 > 其它

cookie的基本用法

2012-03-31 13:42 344 查看
写cookie

 HttpCookie UserCookie = new HttpCookie("userName"); 

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

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

读取cookie

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);

   }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string null user