当前位置: 代码迷 >> JavaScript >> javascript学习(四)Cookie的使用
  详细解决方案

javascript学习(四)Cookie的使用

热度:28   发布时间:2013-04-12 18:33:12.0
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);

  相关解决方案