问题
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 fsdfsd@fsdfsd.de is invalid, can only contain letters or digits.
回答1:
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
};
来源:https://stackoverflow.com/questions/19758575/asp-net-identity-use-email-instead-of-user-name