0
我已經實現了自定義會員供應商,現在我希望爲用戶提供讓網站記住他們的選項,這樣他們就不必每次訪問時都登錄。持久性cookie不會非常持久
我已經將我的cookie設置爲持久性,但它不是非常持久。當我登錄網站後關閉瀏覽器並再次打開時,需要重新登錄。
FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
1,
model.UserName,
DateTime.Now,
(model.RememberMe == true ? DateTime.Now.AddDays(7) : DateTime.Now.AddMinutes(60)),
model.RememberMe,
userData);
string encTicket = FormsAuthentication.Encrypt(authTicket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
Response.Cookies.Add(cookie);
return RedirectToAction("Index", "Home");
model.RememberMe在這種情況下是一個值爲true的布爾值,由Visual Studio調試器驗證。
我在這裏做了些明顯的錯誤嗎?
您正在設置票證的到期日期,而不是過期的Cookie,您應該同時執行以確保Cookie不會過期,並且票證仍被視爲有效 – Slicksim
@Slicksim非常感謝!我會適應它。 – Maritim