【问题标题】:How to change the default generic type for AddDefaultIdentity in Asp.net core 2.2如何在 Asp.net core 2.2 中更改 AddDefaultIdentity 的默认泛型类型
【发布时间】:2019-12-18 02:51:38
【问题描述】:

我创建了一个继承IdentityUserApplicationUser 类,然后在StartUp 类中,我将services.AddDefaultIdentiy 泛型类型从IdentityUser 更改为ApplicationUser,这样我就可以获得UserManager<ApplicationUser> 的服务而不是UserManager<IdentityUser>

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

我收到了这个错误

InvalidOperationException:没有注册类型“Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]”的服务。

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

【问题讨论】:

    标签: asp.net-core asp.net-identity asp.net-core-2.2


    【解决方案1】:

    检查是否将 Views\Shared_LoginPartial.cshtml 中的 IdentityUser 更改为 ApplicationUser 注入

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

    【讨论】:

      猜你喜欢
      • 2019-05-13
      • 2020-05-10
      • 1970-01-01
      • 2015-08-21
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多