日期:2014-05-16 浏览次数:20357 次
创建
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);