首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript学习(四)Cookie的使用

2013-04-12 
javascript学习(4)Cookie的使用创建 HttpCookie cookie new HttpCookie(name)cookie.Value HttpUti

javascript学习(4)Cookie的使用

创建

 HttpCookie cookie = new HttpCookie("name");
            cookie.Value = HttpUtility.UrlDecode("猪刚烈", Encoding.GetEncoding("UTF-8"));   //HttpUtility   这个是用来编码 解码的
            cookie.Expires = DateTime.Now.AddDays(1);    //设置过期时间
            Response.Cookies.Add(cookie);

读取

TextBox1.Text = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["name"].Value, Encoding.GetEncoding("UTF-8"));


删除     只要将过期时间设为负数就删除了。。

HttpCookie cookie = new HttpCookie("name");
            cookie.Expires = DateTime.Now.AddDays(-21);
            Response.Cookies.Add(cookie);

热点排行
Bad Request.