0

In order to ensure that my session always stays on, I created a simple stayalive.aspx page. The header of the page contains metadata to refresh the page every 5 minutes.

In my page-load logic, I simply set a value into session.

protected void Page_Load(object sender, EventArgs e) {
    System.Web.HttpContext.Current.Session["Alive"] = 1;
}

My understanding is that as long as you keep putting a value in the session, the session will continue to stay alive. However, this does not seem to be working. I still get a session timeout in about 30 minutes.

I am wondering if anyone has any insight on why is not working.

Note that the sessionstate as well as forms authentication timeout values in web.config are set to 300 (5 hours).

One thought I had was, instead of setting the same value on the session, I set a different value each time:

    System.Web.HttpContext.Current.Session["Alive"] = DateTime.Now;

Do you think this would help?

istepaniuk
  • 4,016
  • 2
  • 32
  • 60
Peter
  • 11,260
  • 14
  • 78
  • 155
  • 1
    Do you mind sharing why you need the session to not timeout? – The Muffin Man Mar 06 '13 at 23:42
  • You do not actually need anything to call to the session, you just call the page, and the session will update. But are you sure that this page is refreshed ? How the user interact with the rest of your site, they left that page open, and work on some other ? – Aristos Mar 06 '13 at 23:46
  • Check this alternative solution: http://stackoverflow.com/questions/13997778/reset-session-timeout-without-doing-postback-in-asp-net/13998000#13998000 – Aristos Mar 06 '13 at 23:49
  • Thank you for your help. The page is getting refreshed as I display the current time as well on the page. If I doing everything right, why is the session timing out? – Peter Mar 07 '13 at 01:11

1 Answers1

0

Adding a value in to the session is not required to session alive. If you keep on refreshing the aspx page, session should automatically extend.

Nishanth Nair
  • 2,975
  • 2
  • 19
  • 22