Bất cứ ai có thể giải thích tại sao lớp ApplicationUser
tạo ra chức năng trợ giúp sau?ASP.net Identity SecurityStampValidator OnValidateIdentity regenerateIdentity tham số
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;
}
Nơi duy nhất tôi có thể thấy nó đang được sử dụng là trong Startup.Auth.cs tập tin, như thông số regenerateIdentity
gọi lại cho SecurityStampValidator.OnValidateEntity
chức năng:
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User, int>(
validateInterval: TimeSpan.FromSeconds(15),
regenerateIdentityCallback: (manager, user) => user.GenerateUserIdentityAsync(manager),
getUserIdCallback: (id) => id.GetUserId<int>())
Như bạn có thể nhìn thấy từ người trợ giúp nó chỉ quay lại và gọi số manager.CreatedIdentityAsync
. Có lý do nào mà họ "ô nhiễm" lớp ApplicationUser
với phương pháp trợ giúp thay vì thiết lập OnValidateEntity
như sau?
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User, int>(
validateInterval: TimeSpan.FromSeconds(15),
regenerateIdentityCallback: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie),
getUserIdCallback: (id) => id.GetUserId<int>())