2010-12-01 65 views
0

我有一個cookie當用戶包廂: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被刪除。它既沒有過期日期也沒有保存的值。

Whot我做錯了嗎?

+0

你怎麼測試呢?您是否使用瀏覽器嵌入式開發工具(如Firefox的Firebug)來檢查客戶端上cookie的情況? – 2010-12-01 10:19:52

回答

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

應該

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