c# - 配置窗口身份验证在关闭所有并重新打开浏览器 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>
- 启用 Windows 身份验证
- 禁用匿名身份验证
我希望在您立即关闭所有浏览器并重新打开浏览器时打开窗口登录提示:
- 通过浏览器访问我网站的链接
- 窗口登录提示显示,填写用户名和密码
- 经过身份验证并可以处理站点
- 关闭所有浏览器
- 使用访问链接重新打开浏览器
- 应显示窗口登录提示。
问题:
目前第 6 步没有发生,浏览器仍然保持缓存的身份验证。
如果您知道正确的配置,请提供帮助。
谢谢你。
解决方案
您可以使用页面中的 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");
推荐阅读
- rust - 无法释放文件。出现错误:无法编译“libc”
- android - 如何在 Android Studio Java 中将 Json 字符串转换为 Json 数组
- docker - 无法回显 docker 容器中的 env var
- selenium-webdriver - 在线程组和采样器之间传递变量
- java - 线程安全的弹簧数据删除
- angular - 让 Angular Service Worker 只为 Angular 文件工作
- c# - 无法在更高版本的 ASP.NET MVC 框架中使用 Session
- java - 如何使 Instagram 的“分享贴纸资产”示例有效?
- html - 具有来自组件的动态数据更改的反应式表单
- github - 如何在 Azure Artifacts 中从 PR 安全地发布到 NuGet