首页 > 其他 > 详细

Cookies操作

时间:2014-08-12 18:30:34      阅读:345      评论:0      收藏:0      [点我收藏+]

1. http Cookies赋值:

 


                 HttpCookie cookies;
            cookies = new HttpCookie("Fanfenghua");
            cookies.Values.Add("Name", "Fanfenghua"); //添加值
            cookies.Values.Add("Age", "30");
            cookies["Sex"] = "Man";  //另一种赋值模式
            DateTime dt = DateTime.Now.AddHours(20);
            cookies.Expires = dt;  //失效时间
            Response.AppendCookie(cookies);


2. http cookies取值 :

string name="";
            string age="";
            HttpCookie cookies = Request.Cookies["Fanfenghua"];
            if (cookies != null)
            {
                 name = cookies["Name"];
                 age = cookies["Age"];
            }

            Label1.Text = name;
            Label2.Text = age;

3.删除Cookie:

  HttpCookie cookie = Request.Cookies["Fanfenghua"];

            if (cookie != null)
            {
                DateTime dt = DateTime.Now.AddDays(-1);
                cookie.Expires = dt;
                Response.AppendCookie(cookie);
            }

Cookies操作,布布扣,bubuko.com

Cookies操作

原文:http://www.cnblogs.com/fanfh/p/3907815.html

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