Home > ASP.Net, Javascript, Jquery > LogOut User to Login Page If there is no Activity

LogOut User to Login Page If there is no Activity


Hi all,

try this example to LogOut User If there is no Activity


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title>Timeout Test</title>
 <script type="text/javascript" src="jquery-1.9.1.js"></script>
 <script type="text/javascript" src="jquery-ui.min.js"></script>
 <link rel="stylesheet" href="jquery-ui.css" type="text/css" />
 <script>
 // Set timeout variables.
 var timoutWarning = 60000; // Display warning in 1 Min.
 var timoutNow = 120000; // Timeout in 2 Mins.
 var logoutUrl = 'Login.aspx'; // URL to logout page.
 var warningTimer;
 var timeoutTimer;
 // Start timers.
 function StartTimers() {
 warningTimer = setTimeout("IdleWarning()", timoutWarning);
 timeoutTimer = setTimeout("IdleTimeout()", timoutNow);
 }
 // Reset timers.
 function ResetTimers() {
 clearTimeout(warningTimer);
 clearTimeout(timeoutTimer);
 StartTimers();
 $("#timeout").dialog('close');
 }
 // Show idle timeout warning dialog.
 function IdleWarning() {
 $("#timeout").dialog({
 modal: true
 });
 }
 // Logout the user.
 function IdleTimeout() {
 window.location = logoutUrl;
 }
 </script>

<style>
 #timeout
 {
 display: none;
 }
 </style>
</head>
<body onload="StartTimers();" onmousemove="ResetTimers();">
 <form id="form1" runat="server">
 <h1>
 Do not move your mouse!</h1>
 <p>
 If you move your mouse over this window while it is selected it will reset the timer.</p>
 <div id="timeout">
 <h1>
 Session About To Timeout</h1>
 <p>
 You will be automatically logged out in 1 minute.<br />
 To remain logged in move your mouse over this window.
 </div>
 </form>
</body>
</html>

Hope this helps

Good Luck.

Advertisements
Categories: ASP.Net, Javascript, Jquery
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: