ASP.NET Windows身份验证注销
如何在ASP.NET中使用Windows身份验证时注销如此web.config?ASP.NET Windows身份验证注销
<authentication mode="Windows" />
我已经尝试过以下失败。它重定向,但不会注销用户。
void logoutButton_Click(object sender, EventArgs e) {
HttpContext.Current.Session.Clear();
HttpContext.Current.Session.Abandon();
ViewState.Clear();
FormsAuthentication.SignOut();
Response.Redirect("/");
}
背景资料:
我有,因为我需要模拟使用Active Directory来访问本地文件的标识使用Windows身份验证。我不能模仿使用表单身份验证,因为HttpContext.Current.User.Identity
将不是WindowsIdentity
。 Impersonate using Forms Authentication
使用“Windows”身份验证时,服务器端的注销按钮不起作用。如果您需要注销按钮或关闭用户的浏览器,则必须使用“表单”身份验证。
对于仅限IE浏览器,如果使用Windows身份验证,则可以使用以下JavaScript注销用户。 (注意:关闭浏览器不是必需的,但建议用户可能使用的是非IE浏览器)。
如果用户点击“否”关闭浏览器,则当用户尝试访问需要认证的网站上的网页时,系统会提示用户输入用户名/密码。
try {
document.execCommand("ClearAuthenticationCache");
}
catch (e) { }
window.close();
此代码取自SharePoint的Signout.aspx页面。
太棒了!我希望这会在非IE浏览器中导致异常,因此在catch块中,我们可以向非IE用户显示警报,并提供进一步的说明。遗憾的是FF中有一个例外,但不是Chrome。那么,关闭窗户就够了吗?不确定。快速测试表明它可能在Chrome和FF中,但是我确信在IE(没有上述脚本)的情况下,在认证被清除之前需要关闭所有窗口。 – 2012-02-21 15:56:37
我在IE和Firefox中都使用JavaScript来工作,但它会将您在IE中登录的所有内容注销。它在Safari中有点作用,但Safari会发出一个网络钓鱼警告。在Opera中不起作用。
try {
if (document.all)
{
document.execCommand("ClearAuthenticationCache");
window.location = "/";
}
else
{
window.location = "http://logout:[email protected]";
}
}
catch(e)
{
alert("It was not possible to clear your credentials from browser cache. Please, close your browser window to ensure that you are completely logout of system.");
self.close();
}
我已经看到了相关的*问题是找到的最好的答案:
Is there a browser equivalent to IE's ClearAuthenticationCache?
和
Logging a user out when using HTTP Basic authentication
基本上你需要发送一个AJAX请求到服务器无效凭证并让服务器接受它们。
我有一个SharePoint应用程序与Windows身份验证,我需要在15分钟后自动注销。我混合了一些代码,这里是结果。它适用于IE。
<script type="text/javascript">
var t;
window.onload = resetTimer;
document.onmousemove = resetTimer;
document.onkeypress = resetTimer;
function logout() {
try {
document.execCommand("ClearAuthenticationCache");
window.location.href = window.location.protocol.replace(/\:/g, '') + "://" + window.location.host + "/_layouts/customlogin14.aspx";
}
catch (e) { }
}
function resetTimer() {
window.clearTimeout(t);
t = window.setTimeout(logout, 900000);
}
把这些代码在你的母版页,15分钟的空闲时间后,你会看到登录页面。 希望这可以帮助某人
它似乎通过表单身份验证用户毕竟是可能的。见http://*.com/a/11873754/359765 – bgh 2016-07-01 12:21:51