当用户插入时我有一个cookie:
HttpCookie cookie = new HttpCookie("Username");
cookie.Expires = DateTime.Now.AddDays(1.0);
cookie.Value = txtUsername.Text;
Response.Cookies.Add(cookie);
当用户再次访问时,它会在登录页面中读出:
if (Response.Cookies["Username"] != null) txtUsername.Text = Response.Cookies["Username"].Value;
但是当我登录时,之后我直接退出,cookie被删除。它既没有exp-date也没有保存值。
Whot我错了吗?
答案 0 :(得分:6)
if (Response.Cookies["Username"] != null) txtUsername.Text = Response.Cookies["Username"].Value
应该是
if (Request.Cookies["Username"] != null) txtUsername.Text = Request.Cookies["Username"].Value