我有我自己的LINQ到SQL數據庫,有一個很好的登錄方法,它給了我一個用戶。ASP-MVC表單身份驗證 - Cookie不會持久
我跟隨了網上的101個例子來說明如何將cookie添加到客戶端。
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
_u.id.ToString(),
DateTime.Now,
DateTime.Now.AddDays(14),
true,
"hi",
FormsAuthentication.FormsCookiePath);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
//Response.Cookies.Add(cookie);
//FormsAuthentication.RedirectFromLoginPage(_u.name, _remember);
FormsAuthentication.SetAuthCookie(_u.name, _remember);
果然它確實得到了補充。但是當我檢查它時,它的到期表示會話結束,而不是指定的兩週。因此,當用戶在關閉瀏覽器後嘗試返回網站時,他們必須登錄。
任何想法?
_remember是真的嗎?它需要cookie的持久性。 – tvanfosson 2008-11-26 15:34:13