/ Published in: ASP
Call AddKeepAlive() in Page_Load of the page that needs it. Change the path to the correct keep alive page.
Page should disable caching, like in second code snippet.
Page should disable caching, like in second code snippet.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private void AddKeepAlive() { int int_MilliSecondsTimeOut = 2 * 60 * 1000; /*2 minutes*/ //Math.Max((this.Session.Timeout * 60000) - 30000, 5000); string path = VirtualPathUtility.ToAbsolute("~/KeepAlive.aspx"); string str_Script = @"<script>(function(){var r=0,w=window;if (w.setInterval)w.setInterval(function() {r++;var img=new Image(1,1);img.src='" + path + @"?count='+r;}," + int_MilliSecondsTimeOut.ToString() + @");})();</script>"; Page.ClientScript.RegisterStartupScript(typeof(Page), UniqueID + "Reconnect", str_Script); } //[KeepAlive.aspx:] <%@ OutputCache Location="None" VaryByParam="None" %> <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <%=now %> </html>
URL: http://www.codeproject.com/KB/session/Reconnect.aspx