开发者

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
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜