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

感情迁移 提交于 2019-12-28 06:18:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!