laxman Posted February 5, 2009 Posted February 5, 2009 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 Quote
Administrators PlausiblyDamp Posted February 5, 2009 Administrators Posted February 5, 2009 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 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
laxman Posted February 5, 2009 Author Posted February 5, 2009 (edited) 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 Edited February 5, 2009 by laxman Quote
JohnsHandle Posted February 5, 2009 Posted February 5, 2009 (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. Quote
laxman Posted February 6, 2009 Author Posted February 6, 2009 Thank you for ur reply can u suggest me the approach to session capturing if possible with example Quote
JohnsHandle Posted February 6, 2009 Posted February 6, 2009 Like PlausiblyDamp says you can capture the session end event in the global.aspx page. public class Global : System.Web.HttpApplication { .... protected void Session_End(object sender, EventArgs e) { //tidy up code } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.