Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
how to store login intime and logout time in database using session in asp.net c#.In first page username,password and a login button.When i click on login button intime will save on database and redierct to another page where logout button are present.Also,when i click on logout button outtime save in database and redirect on login page.How it is possible using session in asp.net c#.
Posted 16-Dec-12 19:38pm
Comments
Krunal Rohit at 17-Dec-12 1:39am
   
Member 8110943 at 17-Dec-12 1:42am
   
i want to save login intime and outtime in databse using session.
AshishChaudha at 17-Dec-12 5:59am
   
What when user direct close the window?? and not clicking your logout button..
Nandakishorerao at 17-Dec-12 23:37pm
   
ok..here we all help you to sort the problem..but, that doesn't mean we will do the spoon feed..better...try some thing seek the guidance from here (if problem occurs).
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

In Login page: create a session to store user id
 
ex:
Session["userName"] = userName;
 
check in every page that the session value is exist or time out.
 
ex:
if (Session["userName"] != null)
    {
       // TO_DO: initialize your values

     }
     else
{
// suppose your login page name is login.aspx
 Response.Redirect("Login.aspx", false);
}
 

when you click in logout button then redirect in logout.aspx page
 
in Logout.aspx page remove your all session:
 
Session.Abandon();
                   Session.Clear();
                   Session.RemoveAll();
                   System.Web.Security.FormsAuthentication.SignOut();
                   Response.Redirect("Login.aspx", false);
 

please, adjust your code according to this sample code.
 
Thank you.
Rashed:: Bangladesh.
  Permalink  
Comments
Member 8110943 at 17-Dec-12 14:10pm
   
sir,i want to store log intime and outtime in sql database.So,please give me full code..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

ok, thats not problem. just take the current time while login and logout and store in database.
 
 string current_time = DateTime.Now.ToShortTimeString();
  Permalink  

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

  Print Answers RSS
0 CHill60 330
1 OriginalGriff 285
2 Sergey Alexandrovich Kryukov 274
3 BillWoodruff 170
4 Aescleal 140


Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2014
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