首页 > 代码库 > 操作cookies值
操作cookies值
添加cookies:
public const string cookies_Name = "e-biz";
string GUI = System.Guid.NewGuid().ToString("N"); HttpCookie MultiValueCookie = new HttpCookie(cookies_Name+user_name); MultiValueCookie.Values.Add(user_name, GUI); MultiValueCookie.Expires = DateTime.Now.AddDays(10); Response.Cookies.Add(MultiValueCookie);
删除cookies值:
HttpCookie aCookie; string cookieName; int limit = Request.Cookies.Count; for (int i = 0; i < limit; i++) { cookieName = Request.Cookies[i].Name; aCookie = new HttpCookie(cookieName); aCookie.Expires = DateTime.Now.AddDays(-1); Response.Cookies.Add(aCookie); }
读取cookies值:
HttpCookie MultiValueCookie = Request.Cookies[cookies_Name+user_name]; //cookies唯一标识,这里用了固定字符串加动态用户名 if (MultiValueCookie != null) { foreach (string subkey in MultiValueCookie.Values.AllKeys)//循环读取cookies值 { string result = string.Empty; result = MultiValueCookie.Values[user_name]; } }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。