WWW-Authenticate 注销方法
来源:互联网 发布:联通网络解锁助手 编辑:程序博客网 时间:2024/05/01 18:40
目前该方法已经支持IE,Firefox,Chrome
最主要是Chrome的实现方式很恶心,用了sajax,在服务端发送一个WWW-Authenticate
该文章主要参考了http://doc1.fehot.com/2/K/35akhAU.html,然后加入了Chrome的支持
<%
require "sajax"function sys_logout()
cgilua.servervariable('AUTHORIZATION')
cgilua.header('WWW-Authenticate','Basic realm=""');
cgilua.httpstatus(401);
return
endsajax.init()
sajax.export ("sys_logout", sys_logout)
if sajax.handle_client_request () then return end
%><label for="info">logout</label>
<script type="text/javascript">
<%
sajax.show_javascript();
%>function clearAuthenticationCache(page) {
if (!page) page = '/';
try {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("msie") != -1) {
// IE clear HTTP Authentication
document.execCommand("ClearAuthenticationCache");
}
else if (agt.indexOf("firefox") != -1) {
// Let's create an xmlhttp object
var xmlhttp = createXMLObject();
// Let's prepare invalid credentials
xmlhttp.open("GET", page, true, "logout", "logout");
// Let's send the request to the server
xmlhttp.send("");
// Let's abort the request
xmlhttp.abort();
}
else {
document.execCommand("ClearAuthenticationCache");
other_browse_logout();
}
} catch(e) {
// There was an error
return;
}
}
function createXMLObject() {
try {
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
// code for IE
else if (window.ActiveXObject) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
} catch (e) {
xmlhttp=false
}
return xmlhttp;
}
function do_sys_apply(msg)
{
alert('logout')
}function other_browse_logout()
{
x_sys_logout(do_sys_apply)
}
clearAuthenticationCache()
parent.window.location = parent.window.location;
</script>
<script type="text/javascript">
<!--
document.execCommand("ClearAuthenticationCache");
parent.window.location = parent.window.location;
//-->
</script>
说明如下:
1:蓝色字体部分: 对于非ie和firefox的都采用sajax方法进行注销
2:绿色字体部分: 如果没有该语句,sajax注销方式不生效,试过只更新页面上的label标签,无效果
3:红色字体部分: 如果采用sajax方法后,发现IE功能不正常,则再添加此代码后正常
4:本服务端语言为lua
5:clearAuthenticationCache传入的page页面必须要有权限验证,否则在firefox退出不成功
文中的下面语句,我只是让其logout后如果在输入密码,则显示相应的页面而已,大家可以根据自己需要修改或者删除该句话。
parent.window.location = parent.window.location;- WWW-Authenticate 注销方法
- www-authenticate
- www-authenticate
- header WWW-Authenticate认证
- WWW-authenticate 登录验证
- www-authenticate认证过程浅析
- www-authenticate认证过程浅析
- www-authenticate认证过程浅析
- 用WWW-Authenticate实现登录验证
- [转] 用WWW-Authenticate实现登录验证
- www-authenticate与BASE-64认证技术
- [转]www-authenticate认证过程浅析
- Authenticate
- 【HTTP】http 401Basic验证和WWW-Authenticate、Authorization
- sp注销的方法
- 注销账号方法
- 注销远程桌面用户方法
- FormsAuthentication.Authenticate()方法延长保存时间的方法
- orcle 物化视图
- 闭包
- MFC DLL 与 Delphi DLL的互相调用要注意的问题
- Apache Commons Logging 是如何决定使用哪个日志实现类的
- 关于DBGrideh出现Dataset not in edit or insert mode
- WWW-Authenticate 注销方法
- SLF4J教程
- 好的习惯
- VS找不到MFC90d.dll错误
- log4j详解
- 互动网计算机频道图书7日销售排行(05.27-06.02)
- 用Spring提供的test jar包帮助测试用到HTTP request的类
- oUpFileStream.Write Request.BinaryRead (Request.TotalBytes)上传提示错误 0104
- Linux下c++编程与kdevelop的环境配置