如何在 Asp.net 核心 2.2 中更改 AddDefaultIdentity 的默认泛型类型

How to change the default generic type for AddDefaultIdentity in Asp.net core 2.2

我创建了一个继承IdentityUserApplicationUserclass,然后在StartUpclass中,我改变了services.AddDefaultIdentiy泛型从 IdentityUserApplicationUser 所以我可以获得 UserManager<ApplicationUser> 而不是 UserManager<IdentityUser> 的服务。

services.AddDefaultIdentity<ApplicationUser>()
    .AddDefaultUI(UIFramework.Bootstrap4)
    .AddEntityFrameworkStores<ApplicationDbContext>();

我遇到了这个错误

InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered.

而且我无法向服务添加两个默认身份我需要有关如何解决此问题的帮助

检查是否在 Views\Shared_LoginPartial 中将 IdentityUser 更改为 ApplicationUser。cshtml 被注入

@inject SignInManager<ApplicationUser> SignInManager
@inject UserManager<ApplicationUser> UserManager