Sco*_*son 27 asp.net cookies asp.net-identity
使用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);
Run Code Online (Sandbox Code Playgroud)
这是我的启动配置.
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);
Run Code Online (Sandbox Code Playgroud)
DSR*_*DSR 30
在发布身份框架版本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的到期时间不依赖于您在CookieAuthenticationOptions启动时配置的所有用于signIn的方法.
| 归档时间: |
|
| 查看次数: |
20407 次 |
| 最近记录: |