简体   繁体   English

ASP.NET MVC-如何从asp.net网站删除Cookie中的日志

[英]ASP.NET MVC - How do Remove log in Cookies from a asp.net site

How to avoid that when logging in, the browser saves this login data and the user can enter even after closing the browser 如何避免在登录时浏览器保存此登录数据,并且即使关闭浏览器后用户仍可以输入

Thats my login controller 那就是我的登录控制器

 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);
        }
    }

The third parameter to SignInManager.PasswordSignInAsync determines whether or not the cookie will persist after the browser is closed. SignInManager.PasswordSignInAsync的第三个参数确定在关闭浏览器后cookie是否将保留。 If you don't want the cookie to persist, always pass in false for this parameter. 如果您不希望cookie保留,请始终为该参数传递false

See the documentation for this method here - https://docs.microsoft.com/dotnet/api/microsoft.aspnetcore.identity.signinmanager-1.passwordsigninasync?view=aspnetcore-2.2 请在此处查看有关此方法的文档-https: //docs.microsoft.com/dotnet/api/microsoft.aspnetcore.identity.signinmanager-1.passwordsigninasync?view=aspnetcore - 2.2

You could try making the following changes: 您可以尝试进行以下更改:

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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM