如何在关闭应用程序时删除/过期FedAuth Cookie [英] How to delete/expire the FedAuth Cookie on closing the application

查看:160
本文介绍了如何在关闭应用程序时删除/过期FedAuth Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用ADFS为ASP.NET应用程序实现单点登录。每次用户登录应用程序时都会创建联合cookie。当用户关闭应用程序时,联合cookie不会在用户关闭浏览器之前到期。联合cookie在关闭所有浏览器窗口时自动过期。



我想在单击浏览器的关闭(X)按钮时删除联合cookie,而其他浏览器窗口是还开着。联合cookie的名称每次都有所不同,因此我无法根据cookie名称删除cookie。



如何关闭浏览器时删除或过期联合cookie ?

解决方案

这应该在关闭时清除你域中的所有cookie。



  window  .onbeforeunload =  function (){

var cookies = document .cookie.split( ;);

for var i = 0 ; i< cookies.length; i ++){
var cookie = cookies [i];
var eqPos = cookie.indexOf( =);
var name = eqPos> -1? cookie.substr( 0 ,eqPos):cookie;
document .cookie = name + = ; expires =星期四,1970年1月1日00:00:00 GMT;
}
}





来源: http://stackoverflow.com/questions/179355/clearing-all-cookies-with-javascript [ ^ ]



编辑:只需将其包装在

 <   script    类型  =  text / javascript >  <   /   script  >  

标记在页面的任何位置。


Hi,

I am implementing Single Sign-on using ADFS for an ASP.NET application. A federation cookie is created every time the user logs-in to the application. When the user closes the application, the federation cookie does not expire until the user closes the browser. The federation cookie automatically expires on closing all the browser windows.

I want to delete the federation cookie on clicking the Browser's close(X) button while the other browser windows are still open. The name of the federation cookie varies every time so I cannot delete the cookie based on the cookie name.

How can I remove or expire the federation cookie on closing the browser?

解决方案

This should wipe out all cookies from your domain on closing.

window.onbeforeunload = function(){

    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
    	var cookie = cookies[i];
    	var eqPos = cookie.indexOf("=");
    	var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
    	document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}



Source: http://stackoverflow.com/questions/179355/clearing-all-cookies-with-javascript[^]

EDIT: Just wrap that in a

<script type="text/javascript"></script>

tag anywhere on the page.


这篇关于如何在关闭应用程序时删除/过期FedAuth Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆