2012-06-22 124 views

回答

0

通常你会做你签出逻辑当会话结束。但是,如果你有当页面被关闭,检测,使用这样的:

<body onunload="performMyLogoutLogic();"> 
... 
... 
</body> 
+1

这也将注销用户,如果他们仅仅是导航离开从T他说,在同一个网站上的其他页面。 –

-1

你可以使用一个通用的处理程序结束会话,并调用这个beforeunload这样的:

function CloseSession() 
{ 
    location.href = 'KillSession.ashx?task=1'; 
} 
window.onbeforeunload = CloseSession; 

而在你KillSession.ashx为此

public void ProcessRequest(HttpContext context) 
      { 
       if(!String.IsNullOrWhiteSpace(Request.QueryString["task"].toString())) 
       { 
       if(Request.QueryString["task"].toString()=="1") 
        { 
        Session["User"]==null; 
        context.Response.ContentType = "text/plain"; 
        context.Response.Write("Good Bye!"); 
        } 
       } 
      } 
相关问题