Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Comments
[no name] 17-Dec-12 1:39am    
Member 8110943 17-Dec-12 1:42am    
i want to save login intime and outtime in databse using session.
AshishChaudha 17-Dec-12 5:59am    
What when user direct close the window?? and not clicking your logout button..
Nandakishore G N 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).

In Login page: create a session to store user id

ex:
C#
Session["userName"] = userName;


check in every page that the session value is exist or time out.

ex:
C#
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:

C#
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.
 
Share this answer
 
Comments
Member 8110943 17-Dec-12 14:10pm    
sir,i want to store log intime and outtime in sql database.So,please give me full code..
ok, thats not problem. just take the current time while login and logout and store in database.

C#
string current_time = DateTime.Now.ToShortTimeString();
 
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