So I've extended default User class as ;
[Serializable]
public class AUser : IdentityUser<int, AUserLogin, AUserRole, AUserClaim>, IUser , IXmlSerializable
{
public virtual DateTime LastActivity { get; set; }
...
...
}
And I've a method to update user activity
public async void UpdateUserActivity(string userName)
{
var user = _userManager.FindByName(userName);
user.LastActivity = DateTime.UtcNow;
await _userManager.UpdateAsync(user);
}
My purpose here is to keep track of last activity time of users. By last activity time i mean the last time user did any action on the application.
I was planning to call the update method after each request is executed. However, it means executing an update on the database for each request. That sounded expensive to me.
Question : where shall i call it? Is there any better way to keep track of user last activity?
Regards,