Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have made login page.when i click on login ,session is generate.i have to store time of login using session.when i logout ,session will be timeout and time of logout also store using session.

how to check session is timeout and how to store time of login and logout?

i have to do this without javascript.
please help me...
Posted

One approach to do this would be to check for ASP.NET_SessionId in the request.
This neat article[^] explains this approach.

Another approach could be to handle void Session_End(object sender, EventArgs e) in the global.asax file.
 
Share this answer
 
Comments
Member 9511889 7-Jan-13 4:05am    
how to use sessionId ?i hav check your artical but i can't understand..
Hi,

If you have no other option rather than session then use the fallowing Code :

C#
public enum SessionKeys:int
{
Unknown=0,
LogInTime=1,
LogOutTime=2,
IsLoggedIn,3
}


After Log In :
C#
Session[SessionKeys.LogInTime.ToString()]=DateTime.Now;
Session[SessionKeys.IsLoggedIn.ToString()]=true;

After LogOut
C#
Session[SessionKeys.LogOutTime.ToString()]=DateTime.Now;
Session[SessionKeys.IsLoggedIn.ToString()]=false;


Now you can check the session key IsLoggedIn to know whether user is Logged in or not.

if Timeout happened then IsLoggedIn key would be null so your check should me not Null and Not False.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900