Reputation: 898
In an MVC 5 project, with individual user accounts, and facebook login option, how would you log, when a user visits the site, and is already logged in? I have set up a UserLog class, that is created when the user registers on the site, either by register action or from facebok:
public class UserLog
{
public string UserId { get; set; }
public virtual User User { get; set; }
public virtual ICollection<LogonInfo> Logons { get; set; }
}
Every time a user visits the site, I would like to log the date and IP address, and other information in a LogonInfo:
public class LogonInfo
{
public int Id { get; set; }
public string UserLogId { get; set; }
public virtual UserLog UserLog { get; set; }
public DateTime LogonTime { get; set; }
public string IpAddress { get; set; }
public string IpDns { get; set; }
public string Browser { get; set; }
public string OperatingSystem { get; set; }
}
I am not sure how I will get this information, if the user is already logged in when he/se visits the site. My first idea was to just add the information from the Login and ExternalLogin methods on the AccountController, but most users will only log in once, and then just stay logged in whenever they leave and visit the site.
Upvotes: 2
Views: 1680
Reputation: 12032
I strongly recommend you to use TrackerEnabledDbContext.Identity created by Bilal Fazlani. I apply this feature to my project easily and I can log all the changed data on a different table by logging only the changed column instead of all the row entirely.
Upvotes: 1
Reputation: 1742
I would suggest using a filter, you can track the users activity in detail you want, a perfect introduction is on following blog:
https://logcorner.wordpress.com/2013/08/25/asp-net-mvc-tracking-user-activity/
Upvotes: 1