In my website, the server session Timeout is set to 30 minutes.
<system.web>
<sessionState timeout="30" />
</system.web>
However, if a user is actively engaging with the site by typing a long comment or selecting checkboxes, I want to extend their session beyond the specified timeout. For example, if a user becomes inactive after 10 minutes of typing, then returns after 20 minutes, they should not be automatically logged out since the total idle time was only 20 minutes, not the full 30 minutes. I have attempted to implement a code snippet to check for user activity, but it seems to conflict with the web.config settings mentioned earlier. Is there a way to keep the session active when the user is interacting with the browser without resorting to simply redirecting them to logout.aspx? I want to properly end the server session without creating unnecessary dummy pages. Is there a solution using basic Ajax calls to the server without relying on jQuery? Thank you!
var IDLE_TIMEOUT = 60; //seconds
var _idleSecondsCounter = 0;
document.onclick = function() {
_idleSecondsCounter = 0;
};
document.onmousemove = function() {
_idleSecondsCounter = 0;
};
document.onkeypress = function() {
_idleSecondsCounter = 0;
};
window.setInterval(CheckIdleTime, 1000);
function CheckIdleTime() {
_idleSecondsCounter++;
if (_idleSecondsCounter >= IDLE_TIMEOUT) {
alert("Your session has timed out!");
document.location.href = "logout.aspx";
}
}