Store no implementa IUserRoleStore <TUser> ASP.NET Core 2.1 Identity
Estoy usando ASP.NET Core 2.1 Identity. He anulado IdentityUser porque necesito agregar algunas propiedades adicionales en el usuario.
In Startup.cs
services.AddDefaultIdentity<PortalUser>().AddEntityFrameworkStores<ApplicationDbContext>();
ApplicationDbContext.cs
public partial class ApplicationDbContext : IdentityDbContext<PortalUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
}
PortalUser class
public class PortalUser : IdentityUser
{
[PersonalData]
public DateTime? LastLoginDateUtc { get; set; }
[PersonalData]
public DateTime? RegistrationDateUtc { get; set; }
}
Eso está funcionando bien. Puedo agregar un usuario a través de.
_userManager.CreateAsync(user)
Sin embargo, cuando llamo a AddToRolesAsync para agregar un rol a un usuario, obtengo una excepción. ¿Alguna idea de por qué?
_userManager.AddToRolesAsync(user, new List<string> { roleName });
{System.NotSupportedException: Store does not implement IUserRoleStore<TUser>.
at Microsoft.AspNetCore.Identity.UserManager`1.GetUserRoleStore()
at Microsoft.AspNetCore.Identity.UserManager`1.AddToRolesAsync(TUser user, IEnumerable`1 roles)}