User1535942433 posted
Hi kengkit,
As far as I think, you can record the user log in time and log out time in login and log out event! And then you could stored username, logintime and logouttime to the database, then calculate the interval of all records of the user!
In login method:
// inside login method after successful authenticateion then put this
Session["login_time"] = DateTime.Now;
In log out method:
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
}
Or,you could use timespan.
More details,you could refer to below articles:
https://www.c-sharpcorner.com/UploadFile/225740/introduction-of-session-in-Asp-Net/
https://stackoverflow.com/questions/41830817/calculate-each-users-overall-login-period-in-asp-net-c-sharp
Best regards,
Yijing Sun