我正在使用VS2017社区。也忘了提一下,这种情况发生在IE11而不是Chrome中。 我为具有个人用户帐户的MVC应用程序生成默认模板。我点击F5,转到注册,填写字段,但每次,无论如何,表单不发布,我从模型验证得到错误(密码和确认密码不匹配。)。作为复习:
@Secured(closure = {
assert request
assert ctx
authentication.name == 'admin1' || authentication.name == 'admin2' || authentication.name == 'admin3'
})
我尝试了几封电子邮件和密码。我确认我遵循IdentityConfig.cs中的规则来获取密码。
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }
我正在关注一个Pluralsight course并且他们正在做我正在做的没有错误,除了他似乎使用旧版本的Visual Studio。 我已经通过六种方式搜索了这个问题星期日,所有出现的内容都是指MVC的较早实现,其中Compare属性尚未完全实现或者以不同方式实现。 任何人都可以为他们确认/否认这个开箱即用的工作吗?
继承人的后期行动,同样是所有默认的所有模板代码。
// Configure validation logic for passwords
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 6,
RequireNonLetterOrDigit = true,
RequireDigit = true,
RequireLowercase = true,
RequireUppercase = true,
};
只是为了笑容,继承了它生成的默认视图。
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
// For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
// Send an email with this link
// string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
// var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
// await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
// If we got this far, something failed, redisplay form
return View(model);
}
}