[英]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."
]
}
}
您可以配置UserValidator
的UserManager
: RequireUniqueEmail = 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.