62,046
社区成员
发帖
与我相关
我的任务
分享
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
public static class SessionCommon
{
public static bool GetSession(string name)
{
if (HttpContext.Current.Session[name] == null)
{
if (HttpContext.Current.Response.Cookies[name] == null)
{
return false;
}
else
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
HttpContext.Current.Session[name] = HttpUtility.UrlDecode(cookie.Value);
}
return true;
}
return true;
}
public static void SetSessionAndCookie(string name,string value)
{
HttpContext.Current.Session[name] = value;
HttpContext.Current.Response.Cookies[name].Value = HttpUtility.UrlEncode(value);
}
}
HttpCookie cookies = new HttpCookie("test");
cookies.Values["val"] = "110"
cookies.Expires = DateTime.Now.AddMinutes(5);
HttpContext.Current.Response.Cookies.Add(cookies);
HttpCookie cookie = Request.Cookies["QueryStr"];
string sssss = HttpUtility.UrlDecode(cookie.Value);
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"]);
}
string s1 ="select * from 表1 where UID='张三'";
HttpContext.Current.Response.Cookies["QueryStr"].Value = HttpUtility.UrlEncode(s1);