cookie读写

HttpCookie cookie = new HttpCookie("guid");   //创建

cookie.Values["id"] = “123456789”; //将“123456789”写入id

HttpContext.Current.Response.AppendCookie(cookie); //保存

 

HttpCookie cookie  = HttpContext.Current.Request.Cookies[“guid”]; //读取

string id = cookie.Values["id"].ToString(); //id="123456789"

 

cookie.Expires 可以设置过期时间,一般不进行设置默认关闭浏览器后失效

posted @ 2022-03-23 13:29  zwbsoft  阅读(36)  评论(0编辑  收藏  举报