C# 当提交的用户名包含破折号时,无法创建新用户

C# 当提交的用户名包含破折号时,无法创建新用户,c#,asp.net-identity,C#,Asp.net Identity,请帮帮我,我正在尝试使用class IdentityUser()创建一个新的用户,但是当我添加用户名时,破折号(-)符号出现错误。 我怎样才能解决这个问题 var userStore = new UserStore<IdentityUser>(); var manager = new UserManager<IdentityUser>(userStore); var user = new IdentityUser() { UserName = aspNetUsers.E

请帮帮我,我正在尝试使用
class IdentityUser()
创建一个新的用户,但是当我添加
用户名
时,
破折号(-)
符号出现错误。 我怎样才能解决这个问题

var userStore = new UserStore<IdentityUser>();
var manager = new UserManager<IdentityUser>(userStore);

var user = new IdentityUser() { UserName = aspNetUsers.Email };
IdentityResult result = manager.Create(user, aspNetUsers.PasswordHash);
var userStore=new userStore();
var-manager=新的UserManager(userStore);
var user=new IdentityUser(){UserName=aspNetUsers.Email};
IdentityResult result=manager.Create(user,aspNetUsers.PasswordHash);

用户管理器类有一个名为
UserValidator
,在该类中有一个属性需要更改:

public class ApplicationUserManager : UserManager<ApplicationUser>
{
    public ApplicationUserManager(IUserStore<ApplicationUser> store) : base(store)
    {
        this.UserValidator = new UserValidator<ApplicationUser>(this)
        {
            AllowOnlyAlphanumericUserNames = false
        };
    }
}
公共类应用程序管理员:用户管理员
{
公共应用程序服务器管理器(IUserStore存储):基本(存储)
{
this.UserValidator=新的UserValidator(this)
{
AllowOnlyAlphanumericUserNames=false
};
}
}

用户管理器类有一个名为
UserValidator
,在该类中有一个属性需要更改:

public class ApplicationUserManager : UserManager<ApplicationUser>
{
    public ApplicationUserManager(IUserStore<ApplicationUser> store) : base(store)
    {
        this.UserValidator = new UserValidator<ApplicationUser>(this)
        {
            AllowOnlyAlphanumericUserNames = false
        };
    }
}
公共类应用程序管理员:用户管理员
{
公共应用程序服务器管理器(IUserStore存储):基本(存储)
{
this.UserValidator=新的UserValidator(this)
{
AllowOnlyAlphanumericUserNames=false
};
}
}

我也有同样的问题。对于@tparnell提出的解决方案(使用量很大),没有任何变化,验证继续失败

我已通过AccountController中的新声明解决了以下问题:

userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
userManager.UserValidator = new UserValidator<ApplicationUser>(userManager)
        {
            AllowOnlyAlphanumericUserNames = false,
            RequireUniqueEmail = true
        };
userManager=newusermanager(newuserstore(db));
userManager.UserValidator=新的UserValidator(userManager)
{
AllowOnlyAlphanumericUserNames=false,
RequireUniqueEmail=true
};

我也有同样的问题。对于@tparnell提出的解决方案(使用量很大),没有任何变化,验证继续失败

我已通过AccountController中的新声明解决了以下问题:

userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
userManager.UserValidator = new UserValidator<ApplicationUser>(userManager)
        {
            AllowOnlyAlphanumericUserNames = false,
            RequireUniqueEmail = true
        };
userManager=newusermanager(newuserstore(db));
userManager.UserValidator=新的UserValidator(userManager)
{
AllowOnlyAlphanumericUserNames=false,
RequireUniqueEmail=true
};