首页 > 其他 > 详细

操作cookies值

时间:2014-06-26 19:23:14      阅读:276      评论:0      收藏:0      [点我收藏+]

添加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值

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!