如何在新的ASP.NET身份系统中使用电子邮件而不是用户名?
我尝试更改RegisterViewModel
类:
[Display(Name = "Email address")]
[Required(ErrorMessage = "The email address is required")]
[EmailAddress(ErrorMessage = "Invalid Email Address")]
public string UserName { get; set; }
但是当我输入邮件地址时,我收到错误:
User name fsdfsd@fsdfsd.de is invalid, can only contain letters or digits.
答案 0 :(得分:21)
您可以通过关闭该验证程序或创建自己的UserValidator来解决此问题。
你可以这样关掉它:
UserManager.UserValidator = new UserValidator<TUser>(UserManager)
{
AllowOnlyAlphanumericUserNames = false
};