Tuesday, December 11, 2012

Asp.Net Tip : Keep Login Session Alive

Scenario: - Suppose you want to keep the Login session alive for hours. But Keeping Session Alive in money related applications is high risk one and it is not recommended.(e.g Banking Applications.)


Solution:-
To solve this scenario , I found out one simple solution. In Page Load Event of Master page Call the Function as shown below.

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 
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 new page as KeepAlive.aspx and add the below code in the aspx page.

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

Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

0 comments : on " Asp.Net Tip : Keep Login Session Alive "