Hi Ori Cohen,
I will tell you what i have done in my application. I have created an user control and named it as SessionTimeout. And i have pasted the below code:
SessionTimeout.js
var timerPassCount = 0;
var timer; //used to check at every 20 sec the user intercation
var mTimeOut; //is the timeout in seconds specified in sessionstate tag from web.config
var mStrGuid;
function alertMessage() {
Invoked");
}
function InitSessTimeOut(timeout) {
mTimeOut = timeout;
//mStrGuid = strGuid;
document.body.onmouseover = function() { OnMove() };
document.body.onkeypress = function() { OnMove() };
//call the function at 10 sec
timer = setTimeout("timedCount()", 20000);
}
function OnMove() {
if (timerPassCount != 0) {
timerPassCount = 0;
}
}
function timedCount() {
timerPassCount += 20;
if (timerPassCount >= mTimeOut) {
//log out the user
Events_CreateEvent("LogSesOut", true);
Events_RaiseEvents();
return;
}
//call the function at 10 sec
timer = setTimeout("timedCount()", 20000);
}
function LogOut() {
clearTimeout(timer);
}
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 Test
{
/// <summary>
/// Summary description for SessionTimeout
/// </summary>
[ToolboxItem(true)]
[ToolboxBitmapAttribute(typeof(SessionTimeout), "Test.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
{
public delegate void LogOutFct();
public event LogOutFct LogOutEvent;
public SessionTimeout()
{
InitializeComponent();
}
public void Register()
{
this.RegisterSelf();
}
public void SetTimeOut(int timeOut)
{
this.InvokeMethod("alertMessage");
this.InvokeMethodWithId("InitSessTimeOut", new object[] { timeOut });
}
public void LogOut()
{
//stop the client timer
this.InvokeMethodWithId("LogOut");
}
public void Unregister()
{
this.UnRegisterSelf();
}
protected override void FireEvent(IEvent objEvent)
{
switch (objEvent.Type)
{
case "LogSesOut":
{
if (LogOutEvent != null)
LogOutEvent();
}
break;
default:
base.FireEvent(objEvent);
break;
}
}
}
}
SessionTimeout.Designer.cs
namespace Test
{
partial class SessionTimeout
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
FrmMain.cs
And in my main form (which is displayed once the login is successful) i have created a timer and named it as SessionTimer and i have done the below in the main form,
frmMain_Load()
{
SessionTimer.start();
}
private void SessionTimeoutTimer_Tick(object sender, EventArgs e)
{
sessionTimeout.Register();
sessionTimeout.LogOutEvent += new SessionTimeout.LogOutFct(sessionTimeOut_LogOutEvent);
//20 mins by default
int sessTimeOut = 1200;//1200;
System.Web.Configuration.SessionStateSection sessionState = System.Configuration.ConfigurationManager.GetSection("system.web/sessionState") as System.Web.Configuration.SessionStateSection;
if (sessionState != null)
//sessTimeOut = (int)sessionState.Timeout.TotalSeconds;
//sessionTimeout.SetTimeOut(sessTimeOut - SessionTimeoutTimer.Interval / 1000);
sessionTimeout.SetTimeOut(((1 * 120000) / 60000) + 4);
SessionTimeoutTimer.Stop();
}
void sessionTimeOut_LogOutEvent()
{
//logout the session
this.Context.Session.IsLoggedOn = false;
}
I have kept a breakpoint in the SessionTimeout.js in the function InitSessTimeOut(timeout) it doesnt hit the breakpoint at all. Also i have found that in the SessionTimeout.cs file with the below function,
public void SetTimeOut(int timeOut)
{
this.InvokeMethod("alertMessage");
this.InvokeMethodWithId("InitSessTimeOut", new object[] { timeOut });
}
when i see the QuickWatch i am getting the below message "Expression has been evaluated and has no value".
Kindly let me know if i am going wrong somewhere. And i have waited for more than 10 mins and nothing has happened.