2010年6月20日 星期日

[Asp.net]讓Session時間一到讓網頁自動登出

1:<Javascript>   
2:
3: <script type="text/javascript">
4: var sessionTimeout = "<%= Session.Timeout %>";
5: alert(sessionTimeout);
6: function DisplaySessionTimeout()
7: {
8: document.getElementById("<%= lblSessionTime.ClientID %>"). innerText = sessionTimeout;
9: sessionTimeout = sessionTimeout - 1;
10:
11: //if session is not less than 0
12: if (sessionTimeout >= 0)
13: //call the function again after 1 minute delay
14: window.setTimeout("DisplaySessionTimeout()", 60000);
15: else
16: {
17: //show message box
18: window.open('','_self','');
19: window.close();
20: }
21: }
22: </script>
23:
24:
25: <Code_Behind>
26:
27: Session.Timeout = 1;
28: if (!IsPostBack)
29: {
30: Page.ClientScript.RegisterStartupScript(this.GetType(),
31: "onLoad", "DisplaySessionTimeout();", true);
32: }

沒有留言:

張貼留言