Last post Jan 24, 2017 02:56 PM by mohtshm
Jan 22, 2017 08:49 AM|vannessalow|LINK
Hi, I want to calculate the total duration of the users in the webpage.
I want to take datetime of logout - datetime of login (duration of login to logout)
How do i do that in ASP.NET?
Jan 22, 2017 10:10 AM|mohtshm|LINK
You can achieve this by making simple changing in two places
1. In login method after successful login check
2. In logout method
// inside login method after successful authenticateion then put this
Session["login_time"] = DateTime.Now;
if (Session["login_time"] != null)
DateTime loginTime = (DateTime)Session["login_time"];
var loginTimeDurationInMinutes = (DateTime.Now - loginTime).Minutes;
// now put logic to save this duration in db
If any thing still not clear plz let me know
Jan 22, 2017 11:48 AM|vannessalow|LINK
Jan 22, 2017 12:16 PM|mohtshm|LINK
Surely, this is do able and partially done , (per user basis and per login session basis as I already have shown/mentioned now what you've to do is store this in table against user and its login session.
Then for a single user you've to add all its session, And if you want for all users or any subset then need to sum these individual sessions timeouts.
I hope this make sense
Jan 24, 2017 09:06 AM|Eric Du|LINK
According to your description, as far as I know, you can record this user log in time and log out time in log in and log out event! you could stored username, logintime and logouttime to the database, then calculate the interval of all records of somebody!
For more detail, please refer to this tutorial(sample):
ASP.NET - how to store login time and logout time to database:
Jan 24, 2017 01:37 PM|vannessalow|LINK
Hi i already have users' login and logout time in the database, just unsure how to do the calculation, and where to store and call them out afterwards. Thanks!
Jan 24, 2017 02:56 PM|mohtshm|LINK
You could that on any page where you want to display the report for user login duration. As you starts this thread so you must have such view. Are you using entity framework then this is pretty simply by linq to get total and if not then what ever you're
using for db layer just fetch against user id and then in a loop, do the sum. Please try with some code and share with us