[英]Why won't 'Remember Me' work in VS2013's ASP.NET MVC 5 boilerplate code?
使用 VS2013,我創建了一個新項目 -> ASP.NET Web 應用程序 -> 僅 MVC(沒有 WebAPI 或其他任何東西。)
使用 OWIN 創建了大量方便的樣板代碼,包括預期的登錄管理內容。
為了簡單測試,我在 Startup.Auth.cs 中將 CookieAuthentication 選項更改為短超時(添加 ExpireTimeSpan 並設置 validateInterval)。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
ExpireTimeSpan = TimeSpan.FromMinutes(2),
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the user logs in.
// This is a security feature which is used when you change a password or add an external login to your account.
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(1),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
啟動它(F5,它使用 IISExpress 在本地運行並使用 LocalDB),注冊並等待兩分鍾。 單擊“您好,[用戶名]!” 頂部的鏈接(調用 [Authorize]d 控制器方法。)按預期注銷。
再次登錄並選中“記住我”。 等兩分鍾。 單擊相同的鏈接。 再次登出! 為什么是這樣? 我希望無限期登錄。 我誤解了這是做什么的嗎?
我的 System.Web.Mvc.dll 的版本號為 5.2.3-30128.0。
根據這個答案ExpireTimeSpan 在 MVC Identity (2.0.1) 中 regenerateIdentity / validateInterval 持續時間后被忽略
regenerateIdentity
是問題的原因。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.