【问题标题】:how to really logout in asp.net如何在asp.net中真正注销
【发布时间】:2013-11-08 05:48:35
【问题描述】:

我在 asp.net 中使用 LoginControl 登录我的网站,但是当注销时使用登录状态或 session.Abandon 或 .sign out ,有空白退格,我的主页已加载且不安全。

请帮助我在我的项目中使用真正的注销。

【问题讨论】:

  • 注销后“不安全”是什么意思?
  • 当用户注销并单击 backspase 时,他的页面已加载
  • 您遇到了会话和 cookie 问题...确保在您注销时清除它们。

标签: asp.net .net logout login-control


【解决方案1】:

如下使用FormsAuthentication.SignOut();

protected void LogoutButton_Click(object sender, EventArgs e)
{
    FormsAuthentication.SignOut();
    Response.Redirect("~/Login.aspx");
}

【讨论】:

  • 我尝试过,但是当输入退格键时,我的主页已加载
【解决方案2】:

使用 Session.Clear() 就像:

protected void Button_Click(object sender, EventArgs e)
{
Session.Clear();
Response.Redirect("Login.aspx");
}

【讨论】:

    【解决方案3】:

    主页正在从浏览器缓存加载,使用下面的元数据标签强制浏览器在退出页面后清除缓存

    <head runat="server">
    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <meta http-equiv="cache-control" content="no-store" />
    <meta http-equiv="cache-control" content="must-revalidate" />
    <meta http-equiv="cache-control" content="proxy-revalidate" />
    

    【讨论】:

      【解决方案4】:

      我找到了我在母版页中使用的解决方案

      if (Membership.GetUser() != null)
          .....
      else Response.Redirect("Login.aspx")
      

      注销按钮的代码隐藏:

      FormsAuthentication.SignOut();
      Response.Redirect("Login.aspx");
      

      感谢您的帮助!

      【讨论】:

      • 如果Login.aspx使用同一个母版页,这个不行,会导致无限重定向循环,真的很糟糕。
      【解决方案5】:

      没有一个对我有用,但确实如此。

      Context.GetOwinContext().Authentication.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-02-18
        • 2020-09-22
        • 2012-08-16
        • 2014-11-28
        • 2011-02-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多