一般情况下,用户关闭客户端IE时,不会马上执行Session_End事件,而是等Session失效时才会执行Session_End事件,如果想要关闭IE,马上执行Session_End事件可以参考如下方法:

在窗体添加脚本

<script   language= "javascript ">
function   window.onunload()
{
    if   (event.clientX   <0   &&   event.clientY   <0   )
    window.open( "SessionEnd.aspx ", "SessionEnd ");
}
</script>

SessionEnd.aspx页面代码如下

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SessionOut.aspx.cs" Inherits="SessionOut" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>      
        <% Session.Abandon();%>//手动调用session的失效方法
        <script>
            window.close();
        </script>
    </div>
    </form>
</body>
</html>

posted on 2011-04-04 15:29  aparche  阅读(3293)  评论(0编辑  收藏  举报