Handling expired sessions in ASP.NET

by Kevin Goff 13. March 2008 00:17

HOW TO: Send a user to a timeout page when their session has expired using ASP.NET 2.0

ASP.NET

Are your users getting error messages when their session times out? You can easily forward your users on to a page letting them know that their session has expired and they need to begin again. The code below handles this rather gracefully:

    1     void Session_Start(object sender, EventArgs e)

    2     {

    3         // check the header for the presence of the cookie -- if it exists then it is an expired session

    4         string _cookieHeader = System.Web.HttpContext.Current.Request.Headers["Cookie"];

    5         if ((null != _cookieHeader) && (_cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))

    6         {

    7             System.Web.HttpContext.Current.Response.Redirect("/expiredSession.htm");

    8         }

    9     }

Tags: , ,

Comments

3/8/2010 3:00:54 PM #

How to Choose a Financial Advisor

Thanks for the post on Handling expired sessions in ASP.NET. I love your blog most. Anyway, the feature is informative. Keep it up.

How to Choose a Financial Advisor United States | Reply

3/29/2010 8:17:49 AM #

automate job search

Great post.It really contains valuable information.Thanks for sharing.

automate job search United States | Reply

4/27/2010 7:54:06 AM #

internet job posting

Don’t stop writing, you’ve given me lots of good info!

internet job posting United States | Reply

6/18/2010 2:14:02 PM #

plus grand annuaire des casinos en ligne


I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts.Any way Ill be subscribing to your feed and I hope you post again soon...

plus grand annuaire des casinos en ligne India | Reply

7/28/2010 11:01:05 PM #

payday loans

Whoever in discussion adduces authority uses not intellect but memory.

payday loans United States | Reply

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading