M
mark4asp
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
entries.
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
web.config:
<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
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 =
(string)ConfigurationManager.AppSettings["DefaultUrl"];
public SessionTimeOut()
{
//
// Constructor stub
//
}
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
if (this._redirectUrl == null)
throw new InvalidOperationException("RedirectUrl Property Not
Set.");
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)
{
FormsAuthentication.SignOut();
}
Page.Response.Redirect(this._redirectUrl);
}
}
}
}
}
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
entries.
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
web.config:
<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
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 =
(string)ConfigurationManager.AppSettings["DefaultUrl"];
public SessionTimeOut()
{
//
// Constructor stub
//
}
override protected void OnInit(EventArgs e)
{
base.OnInit(e);
if (this._redirectUrl == null)
throw new InvalidOperationException("RedirectUrl Property Not
Set.");
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)
{
FormsAuthentication.SignOut();
}
Page.Response.Redirect(this._redirectUrl);
}
}
}
}
}