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.
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.
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.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)