Qualcuno può spiegare perché la classe ApplicationUser
crea la seguente funzione di supporto?ASP.net Identity SecurityStampValidator OnValidateIdentity regenerateIdentity parameter
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User, int> manager)
{
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
// Add custom user claims here
return userIdentity;
}
L'unico posto dove posso trovarlo in uso è nelle Startup.Auth.cs di file, come il parametro regenerateIdentity
callback per la funzione SecurityStampValidator.OnValidateEntity
:
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User, int>(
validateInterval: TimeSpan.FromSeconds(15),
regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
getUserIdCallback: (id) => id.GetUserId<int>())
Come si può vedere da l'aiutante si gira e chiama lo manager.CreatedIdentityAsync
. C'è una ragione per cui hanno "inquinato" la classe ApplicationUser
con il metodo helper invece di impostare OnValidateEntity
come segue?
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User, int>(
validateInterval: TimeSpan.FromSeconds(15),
regenerateIdentityCallback: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie),
getUserIdCallback: (id) => id.GetUserId<int>())