开发者

ASP.Net Cookie Problems

开发者 https://www.devze.com 2023-01-27 14:20 出处:网络
I have a cookie when a User loges in: HttpCookie cookie = new HttpCookie(\"Username\"); cookie.Expires = DateTime.Now.AddDays(1.0);

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
0

精彩评论

暂无评论...
验证码 换一张
取 消