【问题标题】:'Scheme already exists: Identity.Application' when adding identity when adding another user identity service添加另一个用户身份服务时添加身份时的“方案已存在:Identity.Application”
【发布时间】:2020-09-26 09:52:34
【问题描述】:

我有继承自身份用户的应用程序用户

    public class ApplicationUser : IdentityUser
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string IDNumber { get; set; }
        public string PhysicalAddress { get; set; }
    }

和另一个继承自 ApplicationUser 的 VendorUser

    public class VendorUser : ApplicationUser
    {
        public int? VendorUserId { get; set; }
        public int CardNumber { get; set; }
        public string PhotoIDUrl { get; set; }
    }

如果我在 startup.cs 文件中注册服务,例如:

services.AddIdentity<ApplicationUser, IdentityRole>().AddEntityFrameworkStores<AppDbContext>();
services.AddIdentity<VendorUser, IdentityRole>().AddEntityFrameworkStores<AppDbContext>();

我得到了上面的错误。

如果我不解决它无法解决 VendorUser 的服务。如何解决 VendorUser 的服务而不出现该错误

【问题讨论】:

  • 能否分享一下详细的AppDbContext?您是否为 ApplicationUser 创建两个表,另一个为 VendorUser ?

标签: c# asp.net asp.net-mvc asp.net-core


【解决方案1】:

您不能重复使用 AddIdentity 添加身份。

ASP.NET Core 提供了一个内置方法:AddIdentityCore&lt;TUser&gt;

你可以这样使用它:

 services.AddIdentity<ApplicationUser, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>();
 services.AddIdentityCore<VendorUser>().AddEntityFrameworkStores<ApplicationDbContext>();

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-13
    • 2020-06-25
    • 2017-12-01
    • 1970-01-01
    • 2018-08-01
    • 2016-08-11
    • 2022-01-21
    • 1970-01-01
    相关资源
    最近更新 更多