写入Cookie if (bll.UserLogin(loginUser, loginPwd, out msg, out userModel)) { Session["currUser"] = userModel; if (cbAutoLogin.Checked) { HttpCookie c1 = new HttpCookie("cp1", userModel.LoginId); HttpCookie c2 = new HttpCookie("cp2", this.JiaMi(userModel.LoginPwd)); c1.Expires = DateTime.Now.AddDays(7); c2.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(c1); Response.Cookies.Add(c2); } GoPage(); } 读取Cookie protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null) { string a = Request.Cookies["c1"].Value; string b = Request.Cookies["c2"].Value; UsersModel model = bll.GetMode(a); if (model!=null && model.UserState.Name=="正常") { string result = this.JiaMi(model.LoginPwd, b.Substring(0, 2)); if (result==b) { Session["currUser"] = model; GoPage(); } } } }
为什么 if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null)会始终为空?希望大侠指点一下
那你的 Fillder 抓取下,看看请求和响应中是否有 Cookie。
但是写Cookie的时候有
@残阳tt: 你把抓包贴出来,看下请求和响应
@Launcher: 谢谢了。调出来了,是浏览器上对Cookie进行设置了
客户端是否禁用cookie?
string a = Request.Cookies["c1"].Value;
string b = Request.Cookies["c2"].Value;
这地方是否正确?c1,c2?
有值的,谢谢了。调出来了,是浏览器上对Cookie进行设置了