Я изменил имена таблиц в asp.net core 2.2, но получаю следующую ошибку
InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered.
Думаю, я все сделал. Это мой текущий код.
services.AddDefaultIdentity<ApplicationUser>()
.AddDefaultUI(UIFramework.Bootstrap4)
.AddEntityFrameworkStores<ApplicationDbContext>();
Это мой dbcontext
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Add your customizations after calling base.OnModelCreating(modelBuilder);
builder.Entity<ApplicationUser>().ToTable("User");
builder.Entity<IdentityRole>().ToTable("Role");
builder.Entity<IdentityUserClaim<string>>().ToTable("UserClaim");
builder.Entity<IdentityUserRole<string>>().ToTable("UserRole");
builder.Entity<IdentityUserLogin<string>>().ToTable("UserLogin");
builder.Entity<IdentityRoleClaim<string>>().ToTable("RoleClaim");
builder.Entity<IdentityUserToken<string>>().ToTable("UserToken");
}
}
и это моя модель для ApplicationUser
public class ApplicationUser : IdentityUser
{
}
Что я пропустил? Я верю, что получил все.
Это было в моем _LoginPartial. Спасибо
Проблема в вашем файле Views\Shared\_LoginPartial.cshtml
. В настоящее время ваш _LoginPartial.cshtml
содержит:
@inject SignInManager<IdentityUser> SignInManager
@inject UserManager<IdentityUser> UserManager
Что нужно изменить на:
@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager
Не могли бы вы добавить свой код контроллера? Вероятно, вы пытаетесь ввести
UserManager<IdentityUser>
вместоUserManager<ApplicationUser>