Home > ASP.NET, Javascript > How to implement Auto-Logout functionality in asp.net

How to implement Auto-Logout functionality in asp.net

Here is small code which auto logout the user after 3 minutes.

Untitled Page

// initialize timers
var timer1, timer2;

// resetTimer is a function which reset the timer. if user press any key or move mouse then the timer will reset.
document.onkeypress=resetTimer;
document.onmousemove=resetTimer;

function resetTimer()
{

document.getElementById(‘message’).style.display=’none’;

//clearTimeout() – cancels the setTimeout(). it is inbuilt javascript function.

clearTimeout(timer1);
clearTimeout(timer2);

// waiting time. it is 3 minutes
var waitmin=3;

// alert the user one minute before
timer1=setTimeout(“alertuser()”, (60000*waitmin)-1);

// logout user
timer2=setTimeout(“logout()”, 60000*waitmin);
}

function alertuser()
{
document.getElementById(‘message’).style.display=’block’;
}

function logout()
{
window.location.href=’login.aspx’;
}

Your session is going to expire in 1 minute.
Categories: ASP.NET, Javascript Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment