[英]ASP.NET Identity AuthenticationManager vs. SignInManager and cookie expiration
使用AuthenticationManager SignIn而不是使用SignInManager PasswordSignIn / SignIn有什么區別? 我有一個使用SignInManager的實現,並將我的cookie過期設置為30天,但似乎我的網絡應用程序將在30天之前隨機過期我的cookie。 使用SignInManager實現會導致這種情況嗎? 我應該使用AuthenticationManager實現嗎?
開箱即用的示例代碼顯示了這樣的登錄,但我也看到了其他使用AuthenticationManager實現的示例。
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
這是我的啟動配置。
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
ExpireTimeSpan = TimeSpan.FromDays(30),
LoginPath = new PathString("/signin"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<AppUserManager, AppUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
在發布身份框架版本2.1.0之前,我們必須編寫自己的代碼以獲得結果(SignInStatus)進行雙因素身份驗證,帳戶鎖定,EmailToBeConfirmed等。使用SignInManager,這已經簡化,我們得到SignInStatus一行代碼。
你可以在NuGet包之后理解這個檢查並編譯兩個版本。
版本2.0.0: Install-Package Microsoft.AspNet.Identity.Samples -Version 2.0.0-beta1 -Pre
版本2.1.0: Install-Package Microsoft.AspNet.Identity.Samples -Pre
AuthenticationManager.SignIn
是在SignInManager
后面使用的機制,用於完成用戶signIn過程,因此AuthenticationManager.SignIn
和SignInManager.PasswordSignIn/SignIn
之間沒有任何區別。 我們可以將SignInManager
解釋為一個幫助類來管理所有類型的身份驗證,如PasswordSignIn
/ SignIn
, SignInOrTwoFactor
。
因此,cookie的到期不依賴於您在signA的CookieAuthenticationOptions中配置的CookieAuthenticationOptions
所使用的方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.