How to customize ASP.NET Identity Core Username to allow special characters and space

后端 未结 6 1392
没有蜡笔的小新
没有蜡笔的小新 2020-12-20 18:16

I have changed my Register Action Method to accept user Name instead of Email.

if (ModelState.IsValid)
{
    var user = new ApplicationUser          


        
6条回答
  •  执笔经年
    2020-12-20 18:49

    So cloudikka's answer had it right. I'll just add explicitly (cloudikka's link explained it as well) that you need to list ALL the characters you want to allow (not just the whitespace or special characters), like this:

    services.AddIdentity(options => {
        options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+/ ";
    });
    

    and NOT this options.User.AllowedUserNameCharacters = " "; which means 'only whitespace characters allowed'. (I reckon this was Babar's problem.)

提交回复
热议问题