AllowOnlyAlphanumericUserNames - how to set it? (RC to RTM breaking change) ASP.NET Identity AllowOnlyAlphanumericUserNames - how to set it? (RC to RTM breaking change) ASP.NET Identity asp.net asp.net

AllowOnlyAlphanumericUserNames - how to set it? (RC to RTM breaking change) ASP.NET Identity


In UserManager contructor:

UserValidator = new UserValidator<ApplicationUser>(this) { AllowOnlyAlphanumericUserNames = false };


Yet another way of doing it:

[Authorize]public class AccountController : Controller{    public AccountController()        : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))    {    }    public AccountController(UserManager<ApplicationUser> userManager)    {        UserManager = userManager;        // Start of new code        UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager)        {            AllowOnlyAlphanumericUserNames = false,        };        // End of new code    }    public UserManager<ApplicationUser> UserManager { get; private set; }}


John's answer is right, I used his answer to allow email as username (Wasn't working by default)

Please upvote/accept John's answer.
Here is some code where I used a custom UserManager" to get things working
(This way there's less repeating elsewhere too)

public class MyUserManager : UserManager<ApplicationUser>{    public MyUserManager(DbContext db)        : base(new UserStore<ApplicationUser>(db))    {        this.UserValidator = UserValidator = new UserValidator<ApplicationUser>(this)           { AllowOnlyAlphanumericUserNames = false };    }}

And here's what the AccountController Constructor code looks like now:

[Authorize]public class AccountController : Controller{    public AccountController()        : this(new MyUserManager(new AppContext()))    {    }    public AccountController(UserManager<ApplicationUser> userManager)    {        UserManager = userManager;    }    public UserManager<ApplicationUser> UserManager { get; private set; }