Home > ASP.NET > Keep session alive as long as you want

Keep session alive as long as you want

Most of the time we face problem of session time out . for this there are number of  options are available to solve this like:

Using Web.config file 

    <sessionState mode=”InProc” cookieless=”false” timeout=”15″>
 Set session timeout in Global.asax
void Session_Start(object sender, EventArgs e)
  // Code that runs when a new session is started
  Session.Timeout = 15;
 Set session timeout in IIS

Open IIS manager by typing inetmgr in Start > run in windows.
Right click on websites > Select Properties.

Go to ASP.NET tab, Click on Edit Configuration.
Click on State Management Tab, Set Session TimeOut value (In Minutes).

however all this option not work in some cases or you can say most of the time it does not works. so there is other option for same .

Using Web.config file 

<sessionState mode=”InProc” stateConnectionString=”tcpip=″
 sqlConnectionString=”data source=;Trusted_Connection=yes” cookieless=”false” timeout=”60″/>

Using asp.net handler

step 1) Write a handler

using System;
using System.Web;
using System.Web.Services;
using System.Web.SessionState;

[WebService(Namespace = “http://tempuri.org/&#8221;)]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class myservice: IHttpHandler, IRequiresSessionState
public void ProcessRequest(HttpContext context)
string ulname = context.Request.QueryString[“ulname”];
string ultype = context.Request.QueryString[“ultype”];
if (ultype == “a”)
context.Session[“UserUniqueIdAdmin”] = ulname;
if (ultype == “u”)
context.Session[“UserUniqueId”] = ulname;
if (ultype == “b”)
context.Session[“UserUniqueId”] = ulname;


public bool IsReusable
return false;

now you have written handler , call it from master page or any page using this java script

  <script language=”javascript” type=”text/javascript”>
        $(function() {
            setInterval(myservice123, 10000);
        function myservice123() {

         ” + $(‘#<%     = dn_uid.ClientID %>’).val(), null, function() {
                alert($(‘#<%= Hdn_uid.ClientID %>’).val());


Hope this will solve your problem , comment is welcome for any error in this or any thing you like to share. comment encourage  to write more on issue.


Categories: ASP.NET Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: