0

When I try to create a User with the UserManager and there are characters like ä, ö, ü in the UserName, I get a succeeded=false. I don’t understand why it is a problem. The DB is nvarchar (255) and should not have a problem with German characters. I can change it afterword by using the DbContext. How can I change this behavior?

tmg
  • 19,895
  • 5
  • 72
  • 76
Sknecht
  • 984
  • 2
  • 11
  • 31

1 Answers1

2

Usermanager validates the username by checking if there is any character not contained in the list of allowed characters. You can change that list:

services.Configure<IdentityOptions>(options =>
{
     // The list of allowed characters in the username used to validate user names 
     // you can add German characters here
     options.User.AllowedUserNameCharacters 
        = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+";
});

services.AddIdentity<ApplicationUser, IdentityRole>()
       .AddEntityFrameworkStores<ApplicationDbContext>()
       .AddDefaultTokenProviders();
tmg
  • 19,895
  • 5
  • 72
  • 76