本文介绍了RequireUniqueEmail = false不能正常使用MVC 5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发MVC 5解决方案,在这里我可以管理组织",并且用户可以在其下注册.我实现了帐户控制器,以从注册表单中获取组织ID,并将其保存在AspNetUsers表中.现在,我知道哪个用户属于哪个组织.

I'm developing a MVC 5 solution where I can manage "Organizations" and users can register under them. I implemented the account controller to get the Organization ID from the register form and save it inside the AspNetUsers table. Now I know which user belongs to which organization.

但是现在我有一个问题,每次我尝试使用向另一个组织注册的同一电子邮件注册用户时,都会收到消息:名称t@t.com已被占用".

But now I have a problem, each time I try to register an user using the same email registered to another organization I get the message: "Name t@t.com is already taken."

您知道如何使ASP.NET Membership允许重复的电子邮件吗?

Do you know how to make ASP.NET Membership to allow duplicate emails?

我尝试在我的帐户控制器中使用以下代码,但对我而言不起作用:

I tried to use this code below inside my Account Controller but it did not work for me:

UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager)
{
    RequireUniqueEmail = false
};
var result = await UserManager.CreateAsync(user, model.Password);

有什么想法吗?有更好的方法吗?

Any ideas? Is there a better way of doing it?

推荐答案

问题很可能是您使用电子邮件作为用户名,而不是使用单独的用户名字段.因此,名称t@t.com已被使用-将 t@t.com 视为用户名.创建一个唯一的用户名.

The problem is likely that you're using email as the username rather than having a separate username field. Hence Name t@t.com is already taken - it's treating t@t.com as a username. Create a unique UserName.

这篇关于RequireUniqueEmail = false不能正常使用MVC 5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 00:47