By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Fix for Session Timeout?

P: n/a
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);
}
}
}
}
}

Jun 6 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.