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.
使用表单身份验证进行模拟
Gar*_*ish 23
仅对于IE浏览器,如果使用Windows身份验证,则可以使用以下javascript注销用户.(注意:不需要关闭浏览器,但建议使用浏览器,因为用户可能正在使用非IE浏览器).
如果用户单击"否"关闭浏览器,则如果用户尝试访问需要身份验证的站点上的页面,则会提示用户输入用户名/密码.
try {
document.execCommand("ClearAuthenticationCache");
}
catch (e) { }
window.close();
Run Code Online (Sandbox Code Playgroud)
此代码取自SharePoint的Signout.aspx页面.
我有一个带有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分钟后您将看到登录页面.希望这对某人有所帮助
| 归档时间: |
|
| 查看次数: |
80622 次 |
| 最近记录: |