Configure Microsoft.AspNet.Identity to allow email address as username Configure Microsoft.AspNet.Identity to allow email address as username asp.net asp.net

Configure Microsoft.AspNet.Identity to allow email address as username


You can allow this by plugging in your own UserValidator on the UserManager, or just by turning it off on the default implementation:

UserManager.UserValidator = new UserValidator<TUser>(UserManager) { AllowOnlyAlphanumericUserNames = false }


The C# version of this (in App_Code\IdentityModels.cs) is

public UserManager()        : base(new UserStore<ApplicationUser>(new ApplicationDbContext()))    {        UserValidator = new UserValidator<ApplicationUser>(this) { AllowOnlyAlphanumericUserNames = false };    }


In my case, running in VS 2013 C#, MVC 5.2.2, using ASP.NET Identity 2.0, the solution was to update the ApplicationUserManager constructor inside App_Start\IdentityConfig.cs like so:

public ApplicationUserManager(IUserStore<ApplicationUser> store)        : base(store)    {        this.UserValidator = new UserValidator<ApplicationUser>(this) { AllowOnlyAlphanumericUserNames = false };    }