当 CookieAuthenticationOptions 中的 validateInterval 过期时会发生什么
what happens when validateInterval in the CookieAuthenticationOptions expires
当 validateInterval 超时到期时会发生什么?
这是我的身份验证配置
var cookieAuthOptions = new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Compte/Login"),
CookieDomain = ".rdvdoc.fr",
//si pas défini le cookie expire à la fin de la navigation, définit une durée de validité du cookie
ExpireTimeSpan = TimeSpan.FromDays(365),
//pour étendre la validité du cokie à chaque reconnexion
SlidingExpiration = true,
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the computer 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, User>(
validateInterval: TimeSpan.FromMinutes(60),
regenerateIdentity: (manager, user) => ApplicationUser.GenerateUserIdentityAsync(user, manager))
}
};
我想知道的是:validateidentity 超时后,GenerateUserIdentityAsync 将被调用,但是提供给它的用户对象来自哪里?
- 是否从数据库中重新获取?
- 它是从 cookie 数据重新创建的吗?
- 另一种方式?
谢谢
经理是从 owin 上下文中获取的,用户 ID 从 cookie 中获取。然后从管理器中获取用户。
...
TManager manager = OwinContextExtensions.GetUserManager<TManager>(context.OwinContext);
...
TKey userId = getUserIdCallback(context.Identity);
...
TUser user = await Microsoft.AspNet.Identity.TaskExtensions.WithCurrentCulture<TUser>(manager.FindByIdAsync(userId));
当 validateInterval 超时到期时会发生什么? 这是我的身份验证配置
var cookieAuthOptions = new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Compte/Login"),
CookieDomain = ".rdvdoc.fr",
//si pas défini le cookie expire à la fin de la navigation, définit une durée de validité du cookie
ExpireTimeSpan = TimeSpan.FromDays(365),
//pour étendre la validité du cokie à chaque reconnexion
SlidingExpiration = true,
Provider = new CookieAuthenticationProvider
{
// Enables the application to validate the security stamp when the computer 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, User>(
validateInterval: TimeSpan.FromMinutes(60),
regenerateIdentity: (manager, user) => ApplicationUser.GenerateUserIdentityAsync(user, manager))
}
};
我想知道的是:validateidentity 超时后,GenerateUserIdentityAsync 将被调用,但是提供给它的用户对象来自哪里?
- 是否从数据库中重新获取?
- 它是从 cookie 数据重新创建的吗?
- 另一种方式?
谢谢
经理是从 owin 上下文中获取的,用户 ID 从 cookie 中获取。然后从管理器中获取用户。
...
TManager manager = OwinContextExtensions.GetUserManager<TManager>(context.OwinContext);
...
TKey userId = getUserIdCallback(context.Identity);
...
TUser user = await Microsoft.AspNet.Identity.TaskExtensions.WithCurrentCulture<TUser>(manager.FindByIdAsync(userId));