允许来自同一电子邮件地址的多个帐户 WEB API ASP.NET IDENTITY

Allowing Multiple Accounts from the Same E-Mail Address WEB API ASP.NET IDENTITY

我想使用 asp.net 身份框架 创建多个具有相同电子邮件地址和不同用户名的用户

可能吗?

当我尝试使用相同的电子邮件地址创建用户时出现此错误

{
  "message": "The request is invalid.",
  "modelState": {
    "": [
      "Email 'tester123@live.com' is already taken."
    ]
  }
}

您可以配置 UserValidatorUserManagerRequireUniqueEmail = false。具有个人用户帐户的默认 MVC5 示例代码:

public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) 
{
    var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));

    // Configure validation logic for usernames
    manager.UserValidator = new UserValidator<ApplicationUser>(manager)
    {
        AllowOnlyAlphanumericUserNames = false,
        RequireUniqueEmail = false 
    };

    ...

    return manager;
}

您可能需要在 ApplicationUserManager class 构造函数中设置它:

public ApplicationUserManager(IUserStore<ApplicationUser> store) : base(store)
{
    UserValidator = new UserValidator<ApplicationUser>(this)
    {
        AllowOnlyAlphanumericUserNames = false,
        RequireUniqueEmail = true
    };
 }