首页 > 解决方案 > 配置窗口身份验证在关闭所有并重新打开浏览器 ASP.NET MVC 后显示登录提示

问题描述

我正在使用 Active Directory 使用窗口身份验证。但认证后无法重新打开窗口登录提示。虽然我在重新打开之前关闭了所有浏览器。

我目前的配置:

<authentication mode="Windows" />
    <authorization>
      <deny users="?"/>
    </authorization>`
</authentication>
<membership defaultProvider="ADMembership">
    <providers>
        <add name="ADMembership"
             type="System.Web.Security.ActiveDirectoryMembershipProvider,
                   System.Web, Version=2.0.0.0, Culture=neutral,
                   PublicToken=b03f5f7f11d50a3a"
             connectionStringName="ADConn"
             connectionUsername="domain/user"
             connectionPassword="pwd" />
    </providers>
</membership>
<connectionStrings>  
    <add name="ADConn" 
         connectionString="LDAP://YourConnection" />
</connectionStrings>

我希望在您立即关闭所有浏览器并重新打开浏览器时打开窗口登录提示:

  1. 通过浏览器访问我网站的链接
  2. 窗口登录提示显示,填写用户名和密码
  3. 经过身份验证并可以处理站点
  4. 关闭所有浏览器
  5. 使用访问链接重新打开浏览器
  6. 应显示窗口登录提示。

问题:

目前第 6 步没有发生,浏览器仍然保持缓存的身份验证。

如果您知道正确的配置,请提供帮助。

谢谢你。

标签: c#asp.net-mvcwindows-authentication

解决方案


您可以使用页面中的 javascript 在后台发送常规帖子,并设置一个服务器端代理或服务,如果它没有收到这些常规“心跳”信号,则通过使用 javascript 回发到页面的 unload() 来处理会话


它需要两个步骤

1)检测浏览器是否关闭,如下代码

 window.onbeforeunload = function (event) {
var message = 'Important: Please click on \'Save\' button to leave this page.';
if (typeof event == 'undefined') {
    event = window.event;
}
if (event) {
    event.returnValue = message;
}
return message; $(function () {
$("a").not('#lnkLogOut').click(function () {
    window.onbeforeunload = null;
});
$(".btn").click(function () {
    window.onbeforeunload = null;});});

2)删除缓存的身份验证

 document.execCommand("ClearAuthenticationCache");

推荐阅读