当使用其他pc访问应用程序时,FormsAuthentication.signout()不起作用



我使用以下代码注销:

FormsAuthentication.SignOut();
Session.Abandon();
FormsAuthentication.RedirectToLoginPage();

上面的代码工作正常,当我从我的pc访问我的应用程序。但是如果我从同一网络连接的其他pc上点击我的应用程序,cookie不会被删除,应用程序也不会注销。

用户仍然可以浏览您的网站,因为当您调用FormsAuthentication.SignOut()时cookie不会被清除,并且它们在每个新请求上都经过身份验证。在MS文档中说cookie将被清除,但他们没有,bug?这与'Session.Abandon()',完全相同cookie仍然在那里。

你应该这样修改你的代码:

    FormsAuthentication.SignOut();
    Session.Abandon();
  // clear authentication cookie
  HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
  cookie1.Expires = DateTime.Now.AddYears(-1);
  Response.Cookies.Add(cookie1);
  // clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
  HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
  cookie2.Expires = DateTime.Now.AddYears(-1);
  Response.Cookies.Add(cookie2);
  FormsAuthentication.RedirectToLoginPage();

相关内容

  • 没有找到相关文章