http://aspalliance.com/520_Detecting_ASPNET_Session_Timeouts.2
Base Page and User Control Classes
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public class CustomBasePage : System.Web.UI.Page
{
public CustomBasePage ()
{
}
override protected void OnInit ( EventArgs e )
{
ClearAllNonGlobalSessionsButMine ();
}
private void ClearAllNonGlobalSessionsButMine( )
{
string fileNameNoExt = System.IO.Path.GetFileNameWithoutExtension (
System.Web.HttpContext.Current.Request.Url.AbsolutePath );
for (int i = 0 ; i< HttpContext.Current.Session.Count ;i ++ )
{
string keyValue = HttpContext.Current.Session.Keys [ i ];
if (keyValue.Contains ( fileNameNoExt ) || keyValue.Contains ( "global" ))
{ ; } //do nothing = preserve the value in the session
else
{
Utils.Debugger.WriteIf ( "Deleting ---- " + HttpContext.Current.Session [ HttpContext.Current.Session.Keys [ i ] ] );
HttpContext.Current.Session [ HttpContext.Current.Session.Keys [ i ] ] = null;
} //eof else if it is global or belongs to current page
} //eof loop
} //eof public static void ClearAllButCurrent (string pageName )
} //eof BasePageClass
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!