ASP.NET Windows身份验证注销

Rob*_*ert 48 asp.net windows-authentication logout

如何在ASP.NET中使用Windows身份验证时注销,如此web.config?

<authentication mode="Windows" />
Run Code Online (Sandbox Code Playgroud)

我已经尝试过以下尝试失败了.它重定向,但不会注销用户.

void logoutButton_Click(object sender, EventArgs e) {
    HttpContext.Current.Session.Clear();
    HttpContext.Current.Session.Abandon();
    ViewState.Clear();
    FormsAuthentication.SignOut();
    Response.Redirect("/");
}
Run Code Online (Sandbox Code Playgroud)

背景资料:

我必须使用Windows身份验证,因为我需要使用Active Directory模拟身份以获取对本地文件的访问权限.而且我无法模仿使用Forms身份验证,因为它HttpContext.Current.User.Identity不会是一个WindowsIdentity. 使用表单身份验证进行模拟

Rob*_*ert 33

使用"Windows"身份验证时,服务器端注销按钮不起作用.如果要注销按钮,则必须使用"表单"身份验证,或关闭用户的浏览器.


Gar*_*ish 23

仅对于IE浏览器,如果使用Windows身份验证,则可以使用以下javascript注销用户.(注意:不需要关闭浏览器,但建议使用浏览器,因为用户可能正在使用非IE浏览器).

如果用户单击"否"关闭浏览器,则如果用户尝试访问需要身份验证的站点上的页面,则会提示用户输入用户名/密码.

try {
   document.execCommand("ClearAuthenticationCache");
}
catch (e) { }
window.close();
Run Code Online (Sandbox Code Playgroud)

此代码取自SharePoint的Signout.aspx页面.


tri*_*bus 12

Windows身份验证通过传递Windows身份验证令牌在IIS级别工作.由于身份验证发生在IIS级别,因此无法实际从应用程序代码注销.然而,似乎是一个回答你的问题在这里.这是第二个问题,主要涉及使用表单身份验证和LogonUser Windows API.


Eri*_*ric 6

我有一个带有Windows身份验证的SharePoint应用程序,我需要在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);
} 
Run Code Online (Sandbox Code Playgroud)

将这些代码放在您的母版页中,闲置15分钟后您将看到登录页面.希望这对某人有所帮助