Click here to Skip to main content
13,147,182 members (30,081 online)
Rate this:
 
Please Sign up or sign in to vote.
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 6-Jan-13 19:05pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
Member 9511889 7-Jan-13 4:05am
   
how to use sessionId ?i hav check your artical but i can't understand..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,

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

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


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

After LogOut
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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170915.1 | Last Updated 7 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100