Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Asp.Net Programming

Fix for Session Timeout?

Is this class to fix my Session Timeout problem OK?

The problem is that users are timing out and the timeout then
generates an error entry in the event log. I'd rather not have these

Q1: Is the best place to check for this in the OnInit event?

Q2: How can I test this? I have tried the following setting in
    <sessionState mode="InProc"
      cookieless="false" timeout="1"/>
but it doesn't seem to be timing me out (after 1 minute) !  What could
be going wrong?

using System;
using System.Data;
using System.Configuration;
using System.Web.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Detect Session TimeOut. Redirect to Default page if Timeout
/// </summary>
public class SessionTimeOut : System.Web.UI.Page
  protected string _redirectUrl =

  public SessionTimeOut()
                // Constructor stub
  override protected void OnInit(EventArgs e)

    if (this._redirectUrl == null)
      throw new InvalidOperationException("RedirectUrl Property Not

    if (Context.Session != null)
      if (Context.Session.IsNewSession)
        string sCookieHeader = Page.Request.Headers["Cookie"];
        if ((null != sCookieHeader) &&
(sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
          if (Page.Request.IsAuthenticated)

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc