【问题标题】:`FormsAuthentication.SignOut();` not working for IIS `Windows Authentication` option enabled`FormsAuthentication.SignOut();` 不适用于 IIS `Windows Authentication` 选项已启用
【发布时间】:2012-09-26 09:03:55
【问题描述】:

我的 Visual Studio 2010 C# Web 应用程序中有以下代码。 Web 应用程序在 IIS 中启用了Windows Authentication

<script runat="server">
  void Signout_Click(object sender, EventArgs e)
  {
    FormsAuthentication.SignOut();
    Response.Redirect("WebForm1.aspx");
  }
</script>

<body>
    <form id="form1" runat="server">
    <div>
        <span class="style1"><strong>

        <asp:HyperLink ID="Link_Home" runat="server" NavigateUrl="~/WebForm1.aspx">Home</asp:HyperLink> &nbsp;|
        <asp:Button ID="Submit1" OnClick="Signout_Click" Text="Sign Out" runat="server" />

        </strong></span><br />
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

但是,我注意到FormsAuthentication.SignOut(); 似乎不起作用。这是因为当我单击按钮时。假设注销并清除当前用户,以便当另一个用户来到此页面时,它应该提示输入密码。

但是,当我打开另一个选项卡并输入 Web 应用程序 url 时,它没有提示我输入用户名或密码。只有当网络浏览器关闭并使用网络应用程序 url 再次打开时,它才会提示我输入用户名和密码。

如果有人可以帮助我,不胜感激。

【问题讨论】:

    标签: visual-studio-2010 authentication


    【解决方案1】:

    我使用以下代码注销并重定向到登录页面。

    try {
       document.execCommand("ClearAuthenticationCache");
    }
    catch (e) { }
    window.location.replace("login.aspx");
    

    更多细节和参考如下:

    1. ASP.NET Windows Authentication logout

    2. How to redirect to another webpage in JavaScript/jQuery?

    【讨论】:

      猜你喜欢
      • 2011-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      • 2013-01-14
      • 1970-01-01
      相关资源
      最近更新 更多