Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET identity use email instead of user name [duplicate]

How can I use email instead of user name in the new ASP.NET identity system?

I tried to change the RegisterViewModel class:

[Display(Name = "Email address")]
[Required(ErrorMessage = "The email address is required")]
[EmailAddress(ErrorMessage = "Invalid Email Address")]
public string UserName { get; set; }

but when I enter an mail adress I am getting the error:

User name [email protected] is invalid, can only contain letters or digits.
like image 235
daniel Avatar asked Nov 03 '13 21:11

daniel


Video Answer


1 Answers

You have 2 options to solve it by either turning off that validator, or create your own UserValidator.

You could turn it off like this:

UserManager.UserValidator = new UserValidator<TUser>(UserManager) 
                                    { 
                                       AllowOnlyAlphanumericUserNames = false 
                                    };
like image 182
meda Avatar answered Sep 20 '22 13:09

meda