首页 新闻 赞助 找找看

.net core注册用户如何用户名使用中文名称

1
悬赏园豆:30 [已解决问题] 解决于 2018-08-24 22:49

在IdentityOptions中只有这个AllowedUserNameCharacters选项可以设置,难道把所有汉字全部输入进去,还有其他设置方法吗?

远扬的主页 远扬 | 初学一级 | 园豆:30
提问于:2018-08-24 17:28
< >
分享
最佳答案
0

参考 https://github.com/aspnet/Identity/issues/1848

You'd specify all the allowed characters in the option you mention. But given the large amount of Chinese characters that's probably not going to work for you. Instead try your own UserValidator, using https://github.com/aspnet/Identity/blob/dev/src/Core/UserValidator.cs as a staring point

收获园豆:30
dudu | 高人七级 |园豆:31075 | 2018-08-24 17:46
远扬 | 园豆:30 (初学一级) | 2018-08-24 19:36
dudu | 园豆:31075 (高人七级) | 2018-08-24 21:20

看源码立马就可以找到答案,把 AllowedUserNameCharacters 设置为 null 就行了

else if (!string.IsNullOrEmpty(manager.Options.User.AllowedUserNameCharacters) &&
    userName.Any(c => !manager.Options.User.AllowedUserNameCharacters.Contains(c)))
{
    errors.Add(Describer.InvalidUserName(userName));
}
dudu | 园豆:31075 (高人七级) | 2018-08-24 21:25

@dudu: 谢谢

远扬 | 园豆:30 (初学一级) | 2018-08-24 22:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册