Click here to Skip to main content
Sign Up to vote bad
good
See more: C#ASP.NET
I want to save the login and logout time in current date within single row. Could any one share the coding in C# that will help me.
Posted 21 Dec '12 - 0:13

Comments
AshishChaudha - 21 Dec '12 - 6:20
have you tried anything? dont expect from anybody to write code for you. here all are help if some one getting problem or got stucked..
Member 8110943 - 21 Dec '12 - 6:54
Logout button:- string username = Session["uname"].ToString(); string password = Session["pwd"].ToString(); lbl_1.Text = username; cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "SP_TRACK_USE"; cmd.Parameters.AddWithValue("@Username", username); cmd.Parameters.AddWithValue("@Password", password); cmd.Parameters.AddWithValue("@COMMAND", 1); cmd.ExecuteScalar(); cn.Close(); Response.Redirect("Default.aspx"); and the store procedure for this code :- ALTER PROCEDURE [dbo].[SP_TRACK_USE] @Username varchar(50), @Password varchar(50), @COMMAND INT = 0 AS BEGIN SET NOCOUNT ON; IF(@COMMAND = 0) BEGIN INSERT INTO USERLOG (Username,Password,LOGIN,LOGOUT) VALUES (@Username,@Password,GETDATE(),NULL) END ELSE IF (@COMMAND = 1) BEGIN UPDATE USERLOG SET LOGOUT = GETDATE() WHERE Username=@Username and Password=@Password END END I want that when user click the logout button then it redirect on login page. My code redirect to login page without any error but not save the logout time in database.
Oleksandr Kulchytskyi - 21 Dec '12 - 9:09
Did you invoke Session.Abandon() method after completion all of the logic in logout button ??

2 solutions

Hello Member 8110943,
 
Isn't the problem that when the user is redirected to the login page for the logout the login gets the log out time again?
 
Anyway, I'd suggest that you simply use two different pages, just add one for the log out.
 
Cheers,
Edo
  Permalink  
You may find some anomalies in your data because not everyone will log out through your site. Most logouts will occur when uses simply navigate away from your site or close their browser. In these cases, you won't get an explicit logout that you can apply to your system.
However, the basic logic would be to create the login row in your database when they login leaving the logout field with a value of NULL.(I'm assuming you already have something like that from your question)
On logout, I would suggest that you just need to pull the latest login record for the current user where the logout date is NULL and simply write the current time to that record. If no record is found, then just ignore the logout request and assume the user isn't logged in at all.
But please don't ignore the first part of my answer. There are many things that will happen to mess up your data if you don't write something to clean up these rogue records.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 508
1 Arun Vasu 315
2 Maciej Los 218
3 OriginalGriff 205
4 Aarti Meswania 170
0 Sergey Alexandrovich Kryukov 9,670
1 OriginalGriff 7,409
2 CPallini 3,968
3 Rohan Leuva 3,352
4 Maciej Los 2,861


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid