ASP.NET MVC Identity Email/Username with Special Characters

时间秒杀一切 提交于 2019-12-04 05:11:52

You are setting AllowOnlyAlphanumericUserNames = false in Create method of ApplicationUserManager. Inside the PostRegister action of your ApiController you are newing an instance of ApplicationUserManager. AllowOnlyAlphanumericUserNames is true by default.

You can change the Constructor of ApplicationUserManager

public ApplicationUserManager(IUserStore<ApplicationUser> store): base(store)
{
      UserValidator = new UserValidator<ApplicationUser>(this)
      {
           AllowOnlyAlphanumericUserNames = false,
           RequireUniqueEmail = true
      };
}

That way AllowOnlyAlphanumericUserNames is set to false when you new an instance of ApplicationUserManger.

Note: Its better to get the ApplicationUserManager from OwinContext same as done in AccountController of default MVC5 template or use Dependency Injection.

That's because all your config is in ApplicationUserManager, which you aren't using in your Web Api action. Instead, you're newing up plain-old UserManager, which will then use the defaults for all the validation and such.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!