gpt4 book ai didi

c# - 允许来自同一电子邮件地址的多个帐户 WEB API ASP.NET IDENTITY

转载 作者:太空狗 更新时间:2023-10-30 01:31:22 24 4
gpt4 key购买 nike

我想使用 asp.net 身份框架创建多个用户具有相同的电子邮件地址和不同的用户名

这可能吗?

当我尝试使用相同的电子邮件地址创建用户时出现此错误

{
"message": "The request is invalid.",
"modelState": {
"": [
"Email 'tester123@live.com' is already taken."
]
}
}

最佳答案

您可以配置 UserManagerUserValidator: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
};
}

关于c# - 允许来自同一电子邮件地址的多个帐户 WEB API ASP.NET IDENTITY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41714910/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com