我是MVC的新手,正在从事用户身份验证授权。 我想用UniqueNumber而不是Email更改用户登录凭据。
我尝试过但是它抛出了这个错误
错误1:最佳重载方法匹配项'Microsoft.AspNet.Identity.Owin.SignInManager.PasswordSignInAsync(string,string,bool,bool)'包含一些无效参数
登录操作
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
// This doesn't count login failures towards account lockout
// To enable password failures to trigger account lockout, change to shouldLockout: true
var result = await SignInManager.PasswordSignInAsync(model.UniqueNumber, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
}
LoginViewModel
public class LoginViewModel
{
[Required]
[Display(Name = "Unique Number")]
public int UniqueNumber { get; set; }
[Required]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
}
答案 0 :(得分:1)
考虑到此问题,可能是以下SO answer的副本:
在致电UniqueNumber
时,必须更改用户注册以使用var user = new ApplicationUser { UserName = model.UniqueNumber, Email = model.Email };
而不是电子邮件。
是的,正如@Gonzalo Lorieto所说,您必须将UniqueNumber
转换为字符串。