RequireUniqueEmail = false not working MVC 5

柔情痞子 提交于 2021-02-10 10:55:18

问题


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.

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."

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?


回答1:


You should disable RequiresUniqueEmail in your provider (via web.config settings) Like numerous options can be enabled/disabled

<membership defaultProvider="MySqlMembershipProvider">
  <providers>
    <clear />
    <add connectionStringName="SimpleConnection" applicationName="abc" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="15" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" name="MySqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </providers>
</membership>



回答2:


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.



来源:https://stackoverflow.com/questions/27926574/requireuniqueemail-false-not-working-mvc-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!