Dmitry Guly Dmitry Guly - 1 year ago 126
C# Question

Cannot create new users when submitted username contains dash symbol

Help me please, I'm trying to create a new user user using

class IdentityUser()
, but when I add in my
symbol I get an error.
How can I fix this?

var userStore = new UserStore<IdentityUser>();
var manager = new UserManager<IdentityUser>(userStore);

var user = new IdentityUser() { UserName = aspNetUsers.Email };
IdentityResult result = manager.Create(user, aspNetUsers.PasswordHash);

Answer Source

The user manager class has a called user validator, in that class there is a proptproperty you need to alter

public class ApplicationUserManager : UserManager<ApplicationUser>
    public ApplicationUserManager(IUserStore<ApplicationUser> store) :     base(store)
        this.UserValidator = new UserValidator<ApplicationUser>(this) { AllowOnlyAlphanumericUserNames = false };
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download