Allow multiple accounts from the same email address. WEB API ASP.NET IDENTITY

I want to create several users using the asp.net authentication system with the same email addresses and different usernames .

Is it possible?

When I try to create users with the same email address, I get this error

{
  "message": "The request is invalid.",
  "modelState": {
    "": [
      "Email 'tester123@live.com' is already taken."
    ]
  }
}
+4
source share
1 answer

You can adjust UserValidator UserManager: RequireUniqueEmail = false. Sample code for MVC5 by default with separate user accounts:

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:

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

Source: https://habr.com/ru/post/1667107/


All Articles