Microsoft.AspNet.Identity.UserManager に AllowOnlyAlphanumericUserNames フラグを設定して、UserValidator が英数字以外の UserName を許可するようにするにはどうすればよいですか?
5100 次
6 に答える
12
UserManager コンストラクターで:
UserValidator = new UserValidator<ApplicationUser>(this) { AllowOnlyAlphanumericUserNames = false };
于 2013-10-18T22:58:52.380 に答える
2
ASP.NET Identity 3.0 (現在は RC) の時点で、これはユーザーのオプションとして構成されています。
public void ConfigureServices(IServiceCollection services)
{
// (Rest of code removed)
// Note the + added to the string of allowed user name characters
services.AddIdentity<ApplicationUser, IdentityRole>(o => o.User.AllowedUserNameCharacters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 -._@+")
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
}
Gist と同じコード: https://gist.github.com/pollax/4449ce7cf47bde6b3a95
于 2016-02-28T11:59:07.803 に答える
1
別のやり方
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
// Configure validation logic for usernames
manager.UserValidator = new UserValidator<ApplicationUser>(manager)
{
AllowOnlyAlphanumericUserNames = false,
RequireUniqueEmail = true
};
// Configure validation logic for passwords
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 6,
RequireNonLetterOrDigit = true,
RequireDigit = true,
RequireLowercase = true,
RequireUppercase = true,
};
于 2014-08-08T16:47:48.450 に答える
0
このように独自の UserValidator を作成できます。そしてそれを使用します:
var userManager = new UserManager<ApplicationUser>(new CustomUserStore());
userManager.UserValidator = new CustomUserValidator<ApplicationUser>(userManager);
于 2014-04-11T16:22:47.543 に答える