码迷,mamicode.com
首页 > 其他好文 > 详细

操作cookies值

时间:2014-06-26 19:22:49      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:class   blog   http   string   os   name   

添加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];
                   
                }
            }

 

操作cookies值,布布扣,bubuko.com

操作cookies值

标签:class   blog   http   string   os   name   

原文地址:http://www.cnblogs.com/it888/p/3808332.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!