0

I would like to check whether the session has been timed out or not via ASMX/WCF AJAX call without extending the session.

My Session timeout is 30 minutes. If I am making a AJAX call to check at 15th minute, Session is automatically extending another 30 minutes considering this call a valid user call.

Is there a way to check session has been timed out or not via AJAX call?

Thanks Krish

Krish
  • 131
  • 1
  • 4

1 Answers1

0

Assuming PHP, but this can be any language...

<script>
  var session_timeout = <? echo session_cache_expire(); ?> * 1000;
  setTimeout(function(){
    alert('session is about to expire!');
  },session_timeout - 5000);
</script>

That's how typical sites do it. Save the timeout length on-page, then reference in a script. Could use a prompt() and ask if they want to refresh, then use ajax to "ping" the session.

Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • If users work on multiple browsers sharing the same session, this option does not work. – Krish May 30 '11 at 15:38
  • @Krish: indeed, but you could use [this solution](http://stackoverflow.com/questions/4987582/communication-between-windows-tabs-with-javascript/5148906#5148906) and talk to each tab so they're synchronized. – Brad Christie May 31 '11 at 03:38