【问题标题】:Error with German character in Asp.Net Core IdentityAsp.Net Core Identity 中的德语字符错误
【发布时间】:2016-09-20 09:46:07
【问题描述】:

当我尝试使用 UserManager 创建用户并且用户名中有 ä、ö、ü 之类的字符时,我得到了 succeeded=false。我不明白为什么这是个问题。数据库是 nvarchar (255) 并且应该没有德语字符的问题。我可以通过使用 DbContext 来更改它。我该如何改变这种行为?

【问题讨论】:

    标签: asp.net-identity-3


    【解决方案1】:

    Usermanager 通过检查是否有任何字符未包含在允许的字符列表中来验证用户名。您可以更改该列表:

    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();
    

    【讨论】:

    • 谢谢伙计。还解决了我限制某些标志的问题。 :)
    猜你喜欢
    • 1970-01-01
    • 2020-10-29
    • 2010-09-27
    • 1970-01-01
    • 2012-09-07
    • 2015-10-17
    • 2021-08-15
    • 2020-06-08
    • 2016-08-20
    相关资源
    最近更新 更多