关闭窗口后立即销毁Session
代码如下:
注意:当刷新页面的时候也会触发onunload事件,所以需要判断是否进行关闭再执行Session的销毁操作。即:
if((window.screenLeft>=10000 && window.screenTop>=10000)||event.altKey)
{
}
1<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<html xmlns="http://www.w3.org/1999/xhtml" >
6<head runat="server">
7 <title>无标题页</title>
8<script language="javascript">
9
10function ClosePage()
11{
12if((window.screenLeft>=10000 && window.screenTop>=10000)||event.altKey)
13 {
14 window.location.href="/ClosePage.aspx"
15 }
16}
17
18</script>
19</head>
20<body onunload="ClosePage()">
21 <form id="form1" runat="server">
22 <div>
23 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
24 </form>
25</body>
26</html>
在ClosePage.cs页面的 Page_Load销毁如下: Session.Abandon(); 2
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
5<html xmlns="http://www.w3.org/1999/xhtml" >
6<head runat="server">
7 <title>无标题页</title>
8<script language="javascript">
9
10function ClosePage()
11{
12if((window.screenLeft>=10000 && window.screenTop>=10000)||event.altKey)
13 {
14 window.location.href="/ClosePage.aspx"
15 }
16}
17
18</script>
19</head>
20<body onunload="ClosePage()">
21 <form id="form1" runat="server">
22 <div>
23 <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
24 </form>
25</body>
26</html>
注意:当刷新页面的时候也会触发onunload事件,所以需要判断是否进行关闭再执行Session的销毁操作。即:
if((window.screenLeft>=10000 && window.screenTop>=10000)||event.altKey)
{
}
0
0
(请您对文章做出评价)