1

I retrieve data on ajax call from database in mvc 4 project.I have to check session expiration on ajax call and I set timeout to 1 min..So I put following code in view:

<script type="text/javascript">
    var someSessionVariable = '@Session["key"]';
    if(someSessionVariable == "")
        alert("Session expire");
    else
        alert("Session still exist");  
</script>

Even after 1 min. I get value in someSessionVariable variable and Session still exist alert message display.So how can I check session expiration in this condition.

Thanks

Sukhjeevan
  • 3,074
  • 9
  • 46
  • 89

1 Answers1

0

Configure session expiration in web.config:

<configuration>
  <system.web>
     <sessionState timeout="20"></sessionState>
  </system.web>
</configuration>

timeout is in minutes

UPDATE:

If you are using Chrome, it stopped to handle session cookie expiration some time ago. According to Chrome developers this should improve user experience

http://erlycoder.com/111/google-chrome-session-cookie-expiration-issue-feature-your-personal-data-is-insecure-now-

Chrome issue is marked as WONTFIX https://code.google.com/p/chromium/issues/detail?id=128513

Firefox went this way too https://bugzilla.mozilla.org/show_bug.cgi?id=443354

Also look at this answer Chrome doesn't delete session cookies

Community
  • 1
  • 1
Didar_Uranov
  • 1,230
  • 11
  • 26
  • actually I wasn't asking how to configure session in web.config file. My question is how to track session exist or not on ajax call after timeout meet.I have to redirect user to login if session expire. – Sukhjeevan Apr 30 '14 at 09:43
  • Ok I understand. Session expiration is handled by the browser, see an update – Didar_Uranov Apr 30 '14 at 09:48