But there is a drawback of this approach. Even if user close the browser, session's data will occupy server's memory till 10+ hours and our site's performance will go down. So, this is certainly not a good choice for us.
There are many alternates to solve above problem. In this post, I am sharing one of the possible solution.
First I have created an asmx service i.e. SessionAlive:-
/// Summary description for SessionAlive
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
public class SessionAlive : System.Web.Services.WebService
public void UpdateSession()
HttpContext.Current.Session["tempVariable"] = DateTime.Now;
Also i have created UpdateSession() method which updates a value in session.
Above function calls web service after every minute to ensure that session is not time out. Hopefully this will be useful for you. Feel free to add comments and suggestions.