session有效期问题
作为一个服务器端的状态管理方式,怎么控制session的有效期,在web.config中设置后,不到时间就会结束会话,这个有效期都会被什么原因影响。
<img id="imgSessionAlive" width="1" height="1" /> <script type="text/javascript" > // Helper variable used to prevent caching on some browsers var counter; counter = 0; function KeepSessionAlive() { counter++; var img = document.getElementById ("imgSessionAlive"); img.src = "http://" + counter; (KeepSessionAlive, 60000); } KeepSessionAlive(); </script>使用JQUERY 保持Session
<script language="javascript" type="text/javascript" src="http://code."> </script> <script language="javascript" type="text/javascript"> function KeepSessionAlive() { ("http://"); setInterval(KeepSessionAlive, 60000); } KeepSessionAlive(); </script>
<iframe height="0" width="0" src="RefreshSessionState.aspx" frameborder="0" /> 此时RefreshSessionState.aspx如果你不要跟踪用户的话不需要服务器代码。我习惯于这样写使用 ajax 来保持Session
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax-Refresh.aspx.cs" Inherits="Ajax_Refresh" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www."> <html xmlns="http://www."> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="10000" ontick="Timer1_Tick"> </asp:Timer> <asp:Label ID="Label1" runat="server" Text="Label"> </asp:Label> </ContentTemplate> </asp:UpdatePanel> </div> </form> </body> </html>