Microsoft.AspNet.Identity.UserManager设置UserName可输入中文

Microsoft.AspNet.Identity.UserManager中UserName默认只能输入数字和字母,如果我们需要在userName中输入数字和字母以外的字符,需要对用户验证类中的用户名验证规则进行设置。
设置方式如下:
Microsoft.AspNet.Identity命名空间下用户管理类为UserManager<TUser,TKey>;该类中包含一个用户验证的对象IIdentityValidator类型的 UserValidator;UserValidator中包含一个AllowOnlyAlphanumericUserNames 属性用于标识是否只允许输入数字和字母,系统默认为True;如果我们要输入数字和字母以外的字符,只需将其设置为False即可禁用userName的数字和字母限制。

(UserValidator as UserValidator<User,long>).AllowOnlyAlphanumericUserNames = false;

UserValidator类源码如下图:Microsoft.AspNet.Identity.UserManager设置UserName可输入中文