通过Web API使用"xxx-yyy@gmail.com"等电子邮件注册帐户时,Fiddler会返回以下错误.请注意,电子邮件也用于用户名,因此两个字段都相同.但它在注册MVC本身时有效.
ExceptionMessage =用户创建失败 - 身份异常.错误是:
用户名xx-yyy@gmail.com无效,只能包含字母或数字.
用户对象
var newUser = new ApplicationUser {
UserName = user.Email,
Email = user.Email
};
Run Code Online (Sandbox Code Playgroud)
IdentifyConfig.cs
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) {
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
// Configure validation logic for usernames
manager.UserValidator = new UserValidator<ApplicationUser>(manager) {
RequireUniqueEmail = true,
AllowOnlyAlphanumericUserNames = false
};
Run Code Online (Sandbox Code Playgroud)
我试过注释掉AllowOnlyAlphanumericUserNames,但它没有用.通过将其设置为false应该允许特殊字符,在我的例子中是连字符( - ).
API控制器
// POST: api/auth/register
[ActionName("Register")]
public async Task<HttpResponseMessage> PostRegister(Auth user) {
//dash issue is here.
var userContext …Run Code Online (Sandbox Code Playgroud)