Thursday, March 18, 2010

Keeping Session Live all the time in Asp.net

In Master Page of Page Load Event Call the Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load AddKeepAlive()
End Sub
Private Sub AddKeepAlive() Dim int_MilliSecondsTimeOut As Integer = 2 * 60 * 1000 '2 minutes 'Math.Max((this.Session.Timeout * 60000) - 30000, 5000); Dim path As String = VirtualPathUtility.ToAbsolute("~/KeepAlive.aspx")
Dim str_Script As String = ("<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(GetType(Page), UniqueID & "Reconnect", str_Script) End Sub


Create a Page say as KeepAlive.aspx
Add this in the Page

<%@ OutputCache Location="None" VaryByParam="None" %><?xml version="1.0" encoding="utf-8"?>
<%=now %>

No comments:

Post a Comment