`FormsAuthentication.SignOut();'不工作的IIS的Windows`选项Authentication`启用 [英] `FormsAuthentication.SignOut();` not working for IIS `Windows Authentication` option enabled

查看:107
本文介绍了`FormsAuthentication.SignOut();'不工作的IIS的Windows`选项Authentication`启用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2010中C#Web应用程序下面的code。 Web应用程序有 Windows身份验证在IIS中启用。

I have the following code in my Visual Studio 2010 C# Web Application. The Web application has the Windows Authentication enabled in IIS.

<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(); 似乎不工作。这是因为当我点击按钮。这是假设注销并清除当前用户,这样,当其他用户来到这个页面,就应该提示密码。

However, I notice that the FormsAuthentication.SignOut(); seem not working. This is because when I click the button. It is suppose to logout and clear the current user so that when another user come to this page, it should prompt for password.

然而,当我打开另一个选项卡并输入Web应用程序URL,它并没有提示我输入用户名或密码。只有当Web浏览器与Web应用程序URL关闭并重新打开,那么它提示我输入用户名和密码。

However, when I open another tab and enter the web application url, it did not prompt me for username or password. It is only when the web browser is close and open again with the web application url, then it prompt me for the username and password.

鸭preciate如果有人能帮助我。

Appreciate if anyone can help me.

推荐答案

我用下面的code到注销并重定向到登录页面。

I used the following code to logoff and redirect to the login page.

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

更多细节及参考如下:

More details and Reference as following:


  1. ASP.NET Windows身份验证注销

<一个href=\"http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript\">How我可以做一个重定向页面jQuery的/ JavaScript的?

这篇关于`FormsAuthentication.SignOut();'不工作的IIS的Windows`选项Authentication`启用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆