Session Expiration capturing

laxman

Freshman
Joined
Jun 14, 2008
Messages
28
hi,
i am using in my login page one session variable and assigning the value of username fine this i am getting in required page it is working fine,
all here i want to capture the Session time out how to do that i have tried the below code it is not working can any one help me out with an example or whats wrong in my code the code as follows

the below line i am writing in my login page
Session["UserLoginName"] = TextBox1.Text;

and i am capturing this in another form like this
S_UserLoginName= (string)Session["UserLoginName"];
Lblsession.Text = S_UserLoginName;

this is working fine for capturing expiration in global.asax
void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
Session["CustomSessionId"] = Guid.NewGuid();
}
and in my another form i am checking like this
if (!Page.IsPostBack)
{
if (Session["CustomSessionId"] == null)
{
Response.write("Your session is expired please login again");
}
else
{
}
}

the above code i got it from one site
can any one help me out how to capture session expiration
thank you
 
Should you not be using the Session_End event in global.asax to catch a session ending? Although you do need to be aware that this is never fired if you are storing your session anywhere other than InProc
 
Can you tell me what should i do in global.asax file and also you mentioned every thing (session details) in proc how to do that
 
Last edited:
Code:
(Session["CustomSessionId"] == null)

Will never be true. If your session expires it will just create a new one the next time the user makes a request. You Session_Start event will fire and set the value again right away.

It looks like you want the user to login again when the session expires so you should be setting the Session["CustomSessionId"] when the user authenticates.
 
Thank you for ur reply can u suggest me the approach to session capturing
if possible with example
 
Like PlausiblyDamp says you can capture the session end event in the global.aspx page.

Code:
	public class Global : System.Web.HttpApplication
	{
             ....
		protected void Session_End(object sender, EventArgs e)
		{
                              //tidy up code
		}

	}
 
Back
Top