Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello frienDs !!!

I want to redirect to login page, if the user is idle.

if the user logins with username and password and not uses the application for sometime...more than 10 minutes..It must redirect to login page.

Please can you help me.

Thanks....
Posted
Comments
Maarten Kools 30-Jul-13 6:15am    
Do you want the user to be redirected on the next activity (if so, the solution below should be adequate)? Or automatically? i.e. the user walks away, and comes back to the login page.
HYD Webdeveloper 30-Jul-13 6:19am    
the user walks away, and comes back to the login page.

Ya need this one...if user walks away and come back.

try this javascript code
JavaScript
<script type="text/javascript>

var t;
window.onload=resetTimer;
document.onkeypress=resetTimer;

function logout()
{
	alert("You are now logged out.")
	location.href='Logoff.php' 
}
function resetTimer()
{
	clearTimeout(t);
	t=setTimeout(logout,600000) //logs out in 10 min
}

</script>
 
Share this answer
 
v2
Made session time out 15 min & check for bellow

SQL
Check the user session variable is null or not,if it is null,then redirect to login page.

if (Session["User"] == null)
{  Response.Redirect("Login.aspx");
}
 
Share this answer
 
Comments
HYD Webdeveloper 30-Jul-13 6:19am    
Ya need this one...if user walks away and come back.
C#
using System.Timers;

declare a timer like this
C#
Timer timer = new Timer();
timer.Tick += new EventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
timer.Interval = 1000;             // Timer will tick every 1 seconds
timer.Enabled = true;                       // Enable the timer
timer.Start(); 

now create the event
C#
void timer_Tick(object sender, EventArgs e)
{
     if(Session["user"] == null)
     {
         Response.Redirect("Login.aspx");
     }

}   


In every 1 second your timer will tick and check for the session existence ,if it is null then it will redirect to the login page.
Set the time out for session as 10 mins.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900