日期:2014-05-18 浏览次数:20501 次
string s1 ="select * from 表1 where UID='张三'"; HttpContext.Current.Response.Cookies["QueryStr"].Value = HttpUtility.UrlEncode(queryStr);
string s2 = HttpUtility.UrlDecode(HttpContext.Current.Response.Cookies["QueryStr"].Value);//Value为null
HttpCookie cookie = Request.Cookies["str"]; if (cookie == null) { cookie = new HttpCookie("str"); cookie.Expires = DateTime.Now.AddDays(1); cookie.Values.Add("val", "i am cookie"); Response.Cookies.Add(cookie); Response.Write("cookie已经添加成功"); } else { Response.Write("cookie中读取的值为:"); Response.Write(cookie.Values["val"]); }
------解决方案--------------------
web.config里面要写上支持cookie。
------解决方案--------------------
你的cookie没写进去。
HttpCookie cookies = new HttpCookie("test"); cookies.Values["val"] = "110" cookies.Expires = DateTime.Now.AddMinutes(5); [color=#FF0000]HttpContext.Current.Response.Cookies.Add(cookies);[/color]
------解决方案--------------------