关闭ASP.NET中关闭浏览器或选项卡的会话 [英] Expire session on closing browser or tab in ASP.NET

查看:77
本文介绍了关闭ASP.NET中关闭浏览器或选项卡的会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在关闭浏览器或asp.net中的标签时过期会话。我尝试过以下不符合我要求的解决方案。问题是即使从一个页面导航到另一个页面或刷新页面时也会调用卸载方法。因此,每次用户导航到另一个页面时,它都会使会话无效。



我尝试了什么:



I want to expire session on closing browser or tab in asp.net. I have tried following solutions which are not fulfill my requirement.Problem is that the unload method is called even when you navigate from one page to the other or when you refresh the page. So it invalidates the session every time the user navigates to another page.

What I have tried:

<big>Solution 1:</big>

<body onunload="bodyUnload();" Onclick="clicked=true;">

<script type="text/javascript">
var clicked = false; 
function bodyUnload() 
   {      
      if (clicked == false)//browser is closed  
          {   
         var request = GetRequest();  
           request.open  ("POST", "../LogOut.aspx", false);    
       request.send();    
        } 
   } 
 
   function GetRequest()  
     {       
     var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        return xmlhttp;
      } 
 
</script>

<big>Solution 2 :</big>





函数ajaxFunction()

{

var xmlHttp;

尝试

{

// Firefox,Opera 8.0 +,Safari

xmlHttp = new XMLHttpRequest();

}

catch( e)

{

// Internet Explorer

试试

{

xmlHttp = new ActiveXObject(Msxml2.XMLHTTP);

}

catch(e)

{

try

{

xmlHttp = new ActiveXObject(Microsoft.XMLHTTP);

}

catch(e)

{

alert(您的浏览器不支持AJAX!);

返回false;

}

}

}

xmlHttp.onreadystatechange = function()

{

if(xmlHttp.readyState == 4)

{

document.myForm.time.value = xmlHttp.resp onseText;

}

}

xmlHttp.open(GET,customer_logout.php,true);

xmlHttp.send(null);

}



function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","customer_logout.php",true);
xmlHttp.send(null);
}

推荐答案

如果这是可能的,你不认为asp.net会做开箱即用?无论这个问题多少次被问到,它仍然是不可能的,因为这就是互联网的运作方式。您需要重新设计解决方案,以便在浏览器或选项卡关闭时提出不需要结束会话的内容。
If this was possible don't you think asp.net would do it out of the box? No matter how many times this question is asked it still isn't possible because that's just how the internet works. You need to re-architect your solution to come up with something that doesn't require the session to end when the browser or tab is closed.


这篇关于关闭ASP.NET中关闭浏览器或选项卡的会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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