Search code examples
asp.netajaxsession-timeoutlogout

Asp.net: Implementing Auto-Logout functionality


I have to implement auto-logout functionality in one of my projects and i just cant figure out where to start looking for ideas but SO.

What i need is for the application to redirect the user to the login page if the user session has expired. Please tell me as to what should be my approach to tackle this requirement.

Problem Statement: If the user leaves the system for more than n minutes in any given log-in instance, the system should automatically log them off.


Solution

  • This has been achieved by the following way:

    1) Save the time-stamp of every request( server and ajax excluding the session check ajax request) to the server into a session var.

    2) Poll the server via a JS function using ajax at frequent intervals and check if the time diff between the session time-stamp and the ajax request time is greater than the session timeout val then log-off the current user and return a bool for that ajax request.

    3) Redirect the current page to the login page if the bool returned is true.