Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted (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 by laxman
Posted

(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.

Posted

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
	}

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...