Muh*_*ain 7 c# asp.net identity asp.net-web-api asp.net-identity
我想使用 ASP.NET 身份框架创建多个具有相同电子邮件地址和不同用户名的用户。
是否可以?
当我尝试创建具有相同电子邮件地址的用户时,出现此错误
{
"message": "The request is invalid.",
"modelState": {
"": [
"Email 'tester123@live.com' is already taken."
]
}
}
Run Code Online (Sandbox Code Playgroud)
您可以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;
}
Run Code Online (Sandbox Code Playgroud)
您可能需要在ApplicationUserManager类构造函数中设置它:
public ApplicationUserManager(IUserStore<ApplicationUser> store) : base(store)
{
UserValidator = new UserValidator<ApplicationUser>(this)
{
AllowOnlyAlphanumericUserNames = false,
RequireUniqueEmail = true
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4087 次 |
| 最近记录: |