在http通信中,数据是无状态的,即无法在通信中识别请求用户,于是在客户端浏览器中按照键值对的格式存储一段字符串信息,可以进行状态识别
插件:jquery.cookie.js
写:$.cookie("key","value")
读:$.cookie("key")
后台Cookie
存储
HttpCookie cookie = new HttpCookie("account");
cookie.Expires = DateTime.Now.AddMinutes(20);
cookie.Value = "account";
Response.AppendCookie(cookie);
取值
HttpCookie cookies = Request.Cookies["account"];
if (cookies == null)
{
filterContext.Result = Redirect("/Login");
return;
}
var rkey = cookies.Value;