Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How do I set the AllowOnlyAlphanumericUserNames flag on Microsoft.AspNet.Identity.UserManager so that UserValidator will allow non-alphanumeric UserName?

like image 862
John Palmer Avatar asked Oct 18 '13 21:10

John Palmer


2 Answers

In UserManager contructor:

UserValidator = new UserValidator<ApplicationUser>(this) { AllowOnlyAlphanumericUserNames = false };
like image 109
John Palmer Avatar answered Sep 18 '22 16:09

John Palmer


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; }
}
like image 42
angularsen Avatar answered Sep 19 '22 16:09

angularsen