How do I set the AllowOnlyAlphanumericUserNames flag on Microsoft.AspNet.Identity.UserManager so that UserValidator will allow non-alphanumeric UserName?
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; }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With