Configure Microsoft.AspNet.Identity to allow email address as username

前端 未结 13 2047
时光取名叫无心
时光取名叫无心 2020-11-28 20:08

I\'m in the process of creating a new application and started out using EF6-rc1, Microsoft.AspNet.Identity.Core 1.0.0-rc1, Microsoft.AspNet.Identity.EntityFramework 1.0.0-rc

13条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-28 20:35

    For people on AspNet.Identity.Core 2.1 and up, these validators in the UserManager are readonly. Email addresses as usernames are allowed by default but if you need further customisation of the characters in your usernames, you can do so in Startup.cs like this:

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

    (I needed a '/' for legacy reasons.)

提交回复
热议问题