ASP.Net Cookie Problems
I have a cookie when a User loges in:
HttpCookie cookie = new HttpCookie("Username");
cookie.Expires = DateTime.Now.AddDays(1.0);
cookie.Value = txtUsername.Text;
Response.Cookies.Add(cookie);
and 开发者_运维技巧it reads out in the Login-Page when the user visit again:
if (Response.Cookies["Username"] != null) txtUsername.Text = Response.Cookies["Username"].Value;
But when I log in, and after that I log out directly, the cookie is deleted. It has neither the exp-date nor the value saved.
Whot do I wrong?
if (Response.Cookies["Username"] != null) txtUsername.Text = Response.Cookies["Username"].Value
should be
if (Request.Cookies["Username"] != null) txtUsername.Text = Request.Cookies["Username"].Value
精彩评论