ASP.Net Cookie问题

时间:2010-12-01 10:09:52

标签: asp.net

当用户插入时我有一个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我错了吗?

1 个答案:

答案 0 :(得分:6)

if (Response.Cookies["Username"] != null) txtUsername.Text = Response.Cookies["Username"].Value

应该是

if (Request.Cookies["Username"] != null) txtUsername.Text = Request.Cookies["Username"].Value