1

I have created a heartbeat mechanism to keep the user's session alive. It will run every 60 seconds. Question is, why not set this to like 15 minutes? Also, why use a heartbeat at all; can't I just set my session expiration time in IIS?

I just want to make it so if a user leaves the page for a half hour or so and goes and gets lunch, that they can come back and their session will still be there when they click submit, so they won't lose any data they might have entered before they left.

$(function () {
    // every 60 seconds...
    setInterval(KeepSessionAlive, 60000);
});

function KeepSessionAlive() {
    $.post("/FACTS/_code/Heartbeat.ashx", null, function () {
        //console.log('Session is alive and kicking');
    });
}   
user1477388
  • 20,790
  • 32
  • 144
  • 264
  • 1
    You can. I don't remember off the top of my head, by in my SharePoint silverlight application, mine is set to 20 or 30 minutes. Have you tried turning it up? – tnw May 30 '13 at 12:52
  • Yes, I have turned it up in IIS, so I guess I don't need the heartbeat anymore, right? – user1477388 May 30 '13 at 12:52
  • What makes you say that you won't need the heartbeat at all any more? – tnw May 30 '13 at 12:56
  • If the session is going to live for 2 hours (as I have it set), then I guess I wouldn't need the heartbeat (unless, the user let it sit more than 2 hours...). Maybe I could set the heartbeat to run every 2 hours? What do you think? – user1477388 May 30 '13 at 12:58
  • Try it and find out. I'm honestly not sure. – tnw May 30 '13 at 13:00

1 Answers1

1

This can be configured if you are using Session within the .NET framework.

A snippet from http://msdn.microsoft.com/en-us/library/h6bb9cz9%28v=vs.100%29.aspx describes how to set a timeout parameter in your web.config if you are using SessionState

<configuration>
  <system.web>
    <sessionState 
         mode="[Off|InProc|StateServer|SQLServer|Custom]"
        timeout="number of minutes">
      <providers>...</providers>
    </sessionState>
  </system.web>
</configuration
David L
  • 32,885
  • 8
  • 62
  • 93
  • Do you recommend this over the heartbeat? I don't want any unnecessary calls to the server if I can just extend the half-life of the session. – user1477388 May 30 '13 at 12:53
  • 1
    This is built INTO the server, meaning that you don't have to have constant traffic across the wire to keep the session alive. The server will do it for you. I'd definitely recommend this over the heartbeat. – David L May 30 '13 at 12:55
  • So, how about this method versus increasing the session duration directly in IIS? Ref. http://technet.microsoft.com/en-us/library/cc725820(v=ws.10).aspx – user1477388 May 30 '13 at 12:57
  • 1
    Nope, IIS timeout only applies to classic ASP pages. If you want to manage session timeout, it needs to be done through sessionState in the web.config. – David L May 30 '13 at 13:01
  • Thanks, I did not know that. Here is a reference page if anyone is interested who finds this answer http://stackoverflow.com/questions/1544500/iis-session-timeout-vs-asp-net-session-timeout – user1477388 May 30 '13 at 13:10