首页 > 代码库 > 操作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];                                   }            }