Component Page /BusinessClasses/basePageSessionExpire.cs (C#)
1: using System;  
2:   
3: public class basePageSessionExpire : System.Web.UI.Page  
4: {  
5:     public basePageSessionExpire()  
6:     {  
7:     }  
8:   
9:   
10:     override protected void OnInit(EventArgs e)  
11:     {  
12:         base.OnInit(e);  
13:   
14:   
15:         //It appears from testing that the Request and Response both share the    
16:         // same cookie collection.  If I set a cookie myself in the Reponse, it is    
17:         // also immediately visible to the Request collection.  This just means that    
18:         // since the ASP.Net_SessionID is set in the Session HTTPModule (which    
19:         // has already run), thatwe can't use our own code to see if the cookie was    
20:         // actually sent by the agent with the request using the collection. Check if    
21:         // the given page supports session or not (this tested as reliable indicator    
22:         // if EnableSessionState is true), should not care about a page that does    
23:         // not need session  
24:         if (Context.Session != null)  
25:         {  
26:             //Tested and the IsNewSession is more advanced then simply checking if    
27:             // a cookie is present, it does take into account a session timeout, because    
28:             // I tested a timeout and it did show as a new session  
29:             if (Session.IsNewSession)  
30:             {  
31:                 // If it says it is a new session, but an existing cookie exists, then it must    
32:                 // have timed out (can't use the cookie collection because even on first    
33:                 // request it already contains the cookie (request and response  
34:                 // seem to share the collection)  
35:                 string szCookieHeader = Request.Headers["Cookie"];  
36:                 if ((null != szCookieHeader) && (szCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))  
37:                 {  
38:                     Response.Redirect("default.aspx");  
39:                 }  
40:             }  
41:         }  
42:     }  
43: }

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.