Search KB Filter article types
Session Timeout Control with Warning, Logout, and Browser Close events
Categories: Authentication, Browser Refresh & Suspend
Tags: Developers, Events, Navigation, 1. Beginner, 2. Intermediate, Navigation, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
Revision: 1
Posted: 03/Jan/2009
Updated: 03/Jan/2009
Status: Publish
Types: Article

SessionTimeout.cs
 
#region
 
Using
 
using
System;
 
using
System.Text;
 
using
System.Data;
 
using
System.Drawing;
 
using
System.ComponentModel;
 
using
System.Collections.Generic;
 
using
Gizmox.WebGUI;
 
using
Gizmox.WebGUI.Forms;
 
using
Gizmox.WebGUI.Common;
 
using
Gizmox.WebGUI.Forms.Design;
 
using
Gizmox.WebGUI.Common.Interfaces;
 
using
Gizmox.WebGUI.Common.Extensibility;
 
#endregion
 
namespace
 
{
 
 
 
[
 
[
 
[
 
 
Ccp.Shared.WebGui.Forms[ToolboxItem(true)]ToolboxBitmapAttribute(typeof(SessionTimeout), "Ccp.Shared.WebGui.Forms.Source.SessionTimeout.bmp")]DesignTimeController("Gizmox.WebGUI.Forms.Design.PlaceHolderController, Gizmox.WebGUI.Forms.Design, Version=2.0.5701.0, Culture=neutral, PublicKeyToken=dd2a1fd4d120c769")]ClientController("Gizmox.WebGUI.Client.Controllers.PlaceHolderController, Gizmox.WebGUI.Client, Version=2.0.5701.0, Culture=neutral, PublicKeyToken=0fb8f99bd6cd7e23")]public partial class SessionTimeout : Gizmox.WebGUI.Forms.Component
 
{
 
 
 
 
 
 
int _warningMinutes = 0;int _logoutMinutes = 0;/// <summary>
 
 
/// Fired when a logout is issued.
 
 
/// </summary>
 
 
 
 
public event EventHandler LogOutEvent;/// <summary>
 
 
/// Fired when a user is warned of an impending logout
 
 
/// </summary>
 
 
 
 
public event EventHandler WarningEvent;/// <summary>
 
 
/// Fired when the user closes the browser.
 
 
/// </summary>
 
 
 
 
public event EventHandler CloseEvent;/// <summary>
 
 
/// Ctor
 
 
/// </summary>
 
 
 
{
 
InitializeComponent();
 
 
 
}
 
 
public SessionTimeout()this.RegisterSelf();/// <summary>
 
 
/// Sets the auto logout and warning time thresholds
 
 
/// </summary>
 
 
/// <param name="warningMinutes">The number of idle minutes a session must set before the user is warned.</param>
 
 
/// <param name="logoutMinutes">The number of idle minutes a session must set before the user is logged out. Must be greater than warningMinutes.</param>
 
 
 
{
 
 
 
 
 
_warningMinutes = warningMinutes;
 
_logoutMinutes = logoutMinutes;
 
 
 
 
 
 
 
 
 
 
 
}
 
 
public void SetTimeout(int warningMinutes, int logoutMinutes)if (warningMinutes > logoutMinutes)throw new Exception("warningMinutes cannot be greater than logoutMinutes.");int warningSeconds = warningMinutes * 60;int logoutSeconds = logoutMinutes * 60;this.InvokeMethodWithId("InitSessTimeOut", warningSeconds, logoutSeconds);if (LogOutEvent == null)throw new Exception("The LogOutEvent is not wired. You may also want to wire the WarningEvent.");/// <summary>
 
 
/// The difference between logoutMinutes and warningMinutes.
 
 
/// </summary>
 
 
 
{
 
 
public int MinutesLeadTimeget
 
{
 
 
 
}
 
}
 
 
return _logoutMinutes - _warningMinutes;/// <summary>
 
 
///
 
 
/// </summary>
 
 
/// <param name="objEvent"></param>
 
 
 
{
 
 
 
{
 
 
 
 
 
LogOutEvent(
 
 
 
 
 
 
 
WarningEvent(
 
 
 
 
 
 
 
CloseEvent(
 
 
 
 
 
 
 
 
 
}
 
}
 
}
 
}
protected override void FireEvent(IEvent objEvent)switch (objEvent.Type)case "Logout":if (LogOutEvent != null)this, new EventArgs());break;case "LogoutWarning":if (WarningEvent != null)this, new EventArgs());break;case "Close":if (CloseEvent != null)this, new EventArgs());break;default:base.FireEvent(objEvent);break;
 
 
 
SessionTimeout.js
 
var
_warningSeconds = 0;
 
var
_logoutSeconds = 0;
 
var
_intervalSeconds = 15;
 
var
_warningRaised = false;
 
var
_guid;
 
var
_timer;
 
var
 
 
_timerCounter = 0;
 
function
 
_warningSeconds = warningSeconds;
 
_logoutSeconds = logoutSeconds;
 
_guid = guid;
 
_timer = setTimeout(
 
document.body.onmouseover =
 
document.body.onkeypress =
 
window.onunload =
 
}
InitSessTimeOut(guid, warningSeconds, logoutSeconds) {"checkWarningTimerValues()", _intervalSeconds * 1000);function() { OnMove() };function() { OnMove() };function() { OnClose() };
 
function
 
_timerCounter  = _intervalSeconds;
 
 
 
Events_CreateEvent(_guid,
 
Events_RaiseEvents();
 
clearTimeout(_timer);
 
_timer = setTimeout(
 
_warningRaised =
 
 
 
}
 
_timer = setTimeout(
 
}
checkWarningTimerValues() {if (_timerCounter >= _warningSeconds) {"LogoutWarning", true);"checkLogoutTimerValues()", _intervalSeconds * 1000);true;return;"checkWarningTimerValues()", _intervalSeconds * 1000);
 
function
 
_timerCounter  = _intervalSeconds;
 
 
 
Events_CreateEvent(_guid,
 
Events_RaiseEvents();
 
clearTimeout(_timer);
 
 
 
}
 
_timer = setTimeout(
 
}
checkLogoutTimerValues() {if (_timerCounter >= _logoutSeconds) {"Logout", true);return;"checkLogoutTimerValues()", _intervalSeconds * 1000);
 
function
 
 
 
_timerCounter = 0;
 
 
 
clearTimeout(_timer);
 
_timer = setTimeout(
 
_warningRaised =
 
}
 
}
 
}
 
 
OnMove() {if (_timerCounter != 0) {if (_warningRaised) {"checkWarningTimerValues()", _intervalSeconds * 1000);false;
 
function
 
Events_CreateEvent(_guid,
 
Events_RaiseEvents();
 
}
OnClose() {"Close", true);


About the author

Related Articles

Authentication  
Title Update Author
Tags: Developers, Navigation, 1. Beginner, 2. Intermediate, 3. Advanced, Integration, Navigation, ASP.NET, v6.3, v6.4 and Later
12/Jan/2007    2007/01/12
Tags: Developers, Navigation, 2. Intermediate, 3. Advanced, ASP.NET, Pre v6.3, v6.3, v6.4 and Later
05/Jan/2009    2009/01/05
This video demonstrates how to create a logon form using the form authentication support in Visual WebGui
Tags: Architects, Developers, Windows & Dialogs, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
01/Jan/2009    2009/01/01
This video demonstrates How to create a register form using Visual WebGui
Tags: Architects, Developers, Windows & Dialogs, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
01/Jan/2009    2009/01/01
This video demonstrates How to create a register form using Visual WebGui.
Tags: Architects, Developers, Windows & Dialogs, 1. Beginner, 2. Intermediate, Pre v6.3, v6.3, v6.4 and Later, 3. Advanced
02/Jan/2008    2008/01/02
This is a class to authenticate a user against Microsoft Active directory using the LDAP protocol.
Tags: Architects, Developers, Visual WebGui Pipeline, VB.NET, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
06/Jan/2010    2010/01/06
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS