C# 允许来自同一电子邮件地址的多个帐户WEB API ASP.NET标识
我想使用asp.net identity framework创建多个具有相同电子邮件地址和不同用户名的用户 可能吗 当我尝试创建具有相同电子邮件地址的用户时,会出现此错误C# 允许来自同一电子邮件地址的多个帐户WEB API ASP.NET标识,c#,asp.net,asp.net-web-api,asp.net-identity,identity,C#,Asp.net,Asp.net Web Api,Asp.net Identity,Identity,我想使用asp.net identity framework创建多个具有相同电子邮件地址和不同用户名的用户 可能吗 当我尝试创建具有相同电子邮件地址的用户时,会出现此错误 { "message": "The request is invalid.", "modelState": { "": [ "Email 'tester123@live.com' is already taken." ] } } 您可以配置UserManager的UserValidat
{
"message": "The request is invalid.",
"modelState": {
"": [
"Email 'tester123@live.com' is already taken."
]
}
}
您可以配置
UserManager
的UserValidator
: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;
}
您可以配置
UserManager
的UserValidator
:RequireUniqueEmail=false
谢谢。你节省了我的时间。我已经覆盖了UserManager类和boom。谢谢。请不要在你的帖子中添加乞讨。我已经编辑过一次了,现在您已经回滚了,我将请版主看一下。也
public ApplicationUserManager(IUserStore<ApplicationUser> store) : base(store)
{
UserValidator = new UserValidator<ApplicationUser>(this)
{
AllowOnlyAlphanumericUserNames = false,
RequireUniqueEmail = true
};
}