Avoid Prevent Session TimeOut In Asp.Net To Keep Session Alive

Here i'm explaining How To Avoid Prevent Session TimeOut expiration In Asp.Net 2.0,3,5,4.0 to Keep Session Alive.

We can set timeout value in web.config file using Forms Authentication as mentioned below, Default value is 20 minutes.

This value gets reset or slide if there are calls between client and server and session expiration occurs if idle or no postbacks for specified time.
<authentication mode="Forms"/>
    <sessionState mode="InProc" cookieless="false" timeout="12">

This will cause session to expire if user is inactive for 12 minutes, there are scenarios where you would like to prevent timeout to keep session alive if user goes idle beyond set value in web.config.

Method 1:
We can Write a JavaScript to call a blank or empty page on the server at regular interval which should be little less then value specified in web.config.

I have created a KeepSessionAlive.aspx page and will call it every 10 minutes through JavaScript to slide the expiration.

Method 2:
We can use XMLHttpRequest to interact with server.

Method 3:
We can use timer control with update panel to send requests to server.
<asp:ScriptManager ID="ScriptManager1" runat="server"/>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:Timer ID="Timer1" runat="server" Interval="600000"/>

These methods doesn't need any use interaction or the page to refresh, we can also create and Call WebService Using JQuery Or JavaScript for this.

If you like this post than join us or share


Find More Articles