簡體   English   中英

允許來自同一電子郵件地址的多個帳戶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類構造函數中進行設置:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM