Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai Everyone
I am decide to redirect to login page when website is open and idle for 2 mins,i have 5 to 6 web pages,after login to website it goes to main page,if user not work or it doesn't use for 2 mins when again user click any link or menus one confirm message is appear and redirect to login page and clear all sessions.
Note: May be use time limit in web.config file

Pls reply me asap...

Thans
Aravind
Posted

Below is the sample code of one the way achieving this, sample code will just to give you an idea. Here idle time for testing is 3 second (you can change that). This sample got one text box if user does not click on it with 3 sec interval user will be logged out.

XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

 <script>
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000;// Three Second
function onuser_activite(){
    if(logoutUser){
    alert("You Session Expired");
    window.location.href="/KB/answers/Logout.aspx";
    }
    else{
        ResetLogOutTimer();
    }
}
function OnTimeoutReached(){
logoutUser = true;
}
function ResetLogOutTimer(){
clearTimeout(timeoutHnd);
// set new timer
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}


</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="tbxarea" runat="server" title="Write your name here"></asp:TextBox>
    </div>
    </form>

    <script>document.body.onclick = onuser_activite;
    timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
    </script>
</body>
</html>
 
Share this answer
 
Comments
Aravindba 27-May-13 22:57pm    
Hai Mahesh
I want small changes in ur timeout code,i want automatically open message box when page is idle for 2 mins,in ur code if click any place in page then only it show message box,i want if idle for 2 mins automatically pop up the message box and click ok to login page.
Pls reply asap.

Regards,
Aravind
XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

 <script>
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000;// Three Second
function onuser_activite(){
    if(logoutUser){
    alert("You Session Expired");
    window.location.href="/KB/answers/Logout.aspx";
    }
    else{
        ResetLogOutTimer();
    }
}
function OnTimeoutReached(){
logoutUser = true;
alert("You Session Expired");
    window.location.href="/KB/answers/Logout.aspx";
}
function ResetLogOutTimer(){
clearTimeout(timeoutHnd);
// set new timer
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}


</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="tbxarea" runat="server" title="Write your name here"></asp:TextBox>
    </div>
    </form>

    <script>document.body.onclick = onuser_activite;
    timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
    </script>
</body>
</html>
 
Share this answer
 
Comments
Aravindba 28-May-13 3:48am    
Thank you for your replay,this is works well when i click on page,but i want if idle for 3 secs automatically pop up message box ,i am not click anywhere,pls reply asap

Thanx
Aravind
I just tested below code. Check it
XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

 <script>
var logoutUser = false;
var timeoutHnd = null;
var logouTimeInterval = 3000;// Three Second
function onuser_activite(){
    if(logoutUser){
;
    }
    else{
        ResetLogOutTimer();
    }
}
function OnTimeoutReached(){
logoutUser = true;
    alert("You Session Expired");
    window.location.href="/KB/answers/Logout.aspx";

}
function ResetLogOutTimer(){
clearTimeout(timeoutHnd);
// set new timer
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
}


</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="tbxarea" runat="server" title="Write your name here"></asp:TextBox>
    </div>
    </form>

    <script>document.body.onclick = onuser_activite;
    timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
    </script>
</body>
</html>
 
Share this answer
 
Comments
Aravindba 28-May-13 4:53am    
Hi
in this if click event is occur then only it show message box, in form tag u writ like this
<script>document.body.onclick = onuser_activite;
timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval);
</script>
this is occour when user click on boby it show message box,i want without any click event or mouse over.it automatically show the message box.
Mahesh Bailwal 28-May-13 5:09am    
have you tested?

document.body.onclick = onuser_activite; is used to rest timer if user clicks where else timeoutHnd = setTimeout('OnTimeoutReached();',logouTimeInterval); is start timer as soon as page get loaded.

Please test code given in my last reply and let me know.
Aravindba 28-May-13 6:17am    
Hai Mahesh
i will check that code,if i click page ,if idle 3 secs it show error message box, it not automatically show message box when page is idle for 3 secs,i will wait fro 5 mins but it not show error message box. how OnTimeoutReached() function is invoked ? can u explain me ,OnTimeoutReached() funtion automatically invoked when page is idle for 3 secs ?
Aravindba 31-May-13 3:24am    
Hi If i use in single page it works correctly,but in web site i have master page also ,this code i have to write in master page also ? or i use child page only ? if i use child page where i write code,bcz child page have only contentplace holder not have head,body form,pls reply me
Aravindba 3-Jun-13 2:10am    
hi mahesh
pls reply me,ur code work when i click text box then only it pop up alert message,but i want if open page and idle for 3 secs it automatically pop up alert message box.
 
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