如何避免登录时,浏览器保存此登录数据,即使关闭浏览器
,用户也可以输入。那是我的登录控制器
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
var userDTO = new ExpandedUserDTO();
switch (result)
{
case SignInStatus.Success:
ApplicationUser user = await UserManager.FindAsync(model.Email, model.Password);
return RedirectToAction("RedirectLogin");
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Falha ao Realizar login, usuário ou senha incorretos.");
return View(model);
}
}
SignInManager.PasswordSignInAsync
的第三个参数确定浏览器关闭后cookie是否会持续。如果您不希望Cookie持续存在,请始终通过false
输入此参数。
在此处查看此方法的文档-https://lealen.microsoft.com/dotnet/api/microsoft.aspnetcore.identity.signinmanager-1.passwordsignInAsyNAce?
您可以尝试进行以下更改:
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, false, shouldLockout: false);
var userDTO = new ExpandedUserDTO();
switch (result)
{
case SignInStatus.Success:
ApplicationUser user = await UserManager.FindAsync(model.Email, model.Password);
return RedirectToAction("RedirectLogin");
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Falha ao Realizar login, usuário ou senha incorretos.");
return View(model);
}
}