如何设置AllowOnlyAlphanumericUserNames ?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (291)

如何设置Microsoft.AspNet.Identity.UserManager上的AllowOnlyAlphanumericUserNames flag

,以便UserValidator允许非字母数字的用户名?

提问于
用户回答回答于

另一种方法是:

[Authorize]
public class AccountController : Controller
{
    public AccountController()
        : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
    {
    }

    public AccountController(UserManager<ApplicationUser> userManager)
    {
        UserManager = userManager;

        // Start of new code
        UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager)
        {
            AllowOnlyAlphanumericUserNames = false,
        };
        // End of new code
    }

    public UserManager<ApplicationUser> UserManager { get; private set; }
}
用户回答回答于

在UserManager结构中:

UserValidator = new UserValidator<ApplicationUser>(this) { AllowOnlyAlphanumericUserNames = false };

扫码关注云+社区

领取腾讯云代金券