所以我有一个.Net Core MVC Webapp,Windows身份验证启动并运行 . 现在需要注销功能,以便其他用户可以登录 .
尽管客户端绑定了,但是当客户端第一次调用URL时,应用程序会显示一个登录弹出窗口(Browserstyle) . 正常的.Net MVC中有一些解决方法可以再次获得此提示:
'Login as another user' MVC 4 Windows Authentication

public ActionResult LogOut()
{
    HttpCookie cookie = Request.Cookies["TSWA-Last-User"];

    if(User.Identity.IsAuthenticated == false || cookie == null || StringComparer.OrdinalIgnoreCase.Equals(User.Identity.Name, cookie.Value))
    {
        string name = string.Empty;

        if(Request.IsAuthenticated)
        {
            name = User.Identity.Name;
        }

        cookie = new HttpCookie("TSWA-Last-User", name);
        Response.Cookies.Set(cookie);

        Response.AppendHeader("Connection", "close");
        Response.StatusCode = 401; // Unauthorized;
        Response.Clear();
        //should probably do a redirect here to the unauthorized/failed login page
        //if you know how to do this, please tap it on the comments below
        Response.Write("Unauthorized. Reload the page to try again...");
        Response.End();

        return RedirectToAction("Index");
    }

    cookie = new HttpCookie("TSWA-Last-User", string.Empty)
    {
        Expires = DateTime.Now.AddYears(-5)
    };

    Response.Cookies.Set(cookie);

    return RedirectToAction("Index");

}

如何在.Net Core中实现相同的功能?在.Net Core中编辑正确的cookie并操纵响应有几个困难 . 我试图找到最少的hacky方式 .