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

时间:2017-01-18 08:52:04

标签: c# asp.net asp.net-web-api asp.net-identity identity

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

有可能吗?

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

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

1 个答案:

答案 0 :(得分:3)

您可以配置UserValidator的{​​{1}}:UserManager。具有个人用户帐户的默认MVC5的示例代码:

RequireUniqueEmail = false

您可能需要在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