protected void Session_Start(Object sender, EventArgs e) { using (ApplicationDbContext db = new ApplicationDbContext()) { string sessionId = HttpContext.Current.Session.SessionID.ToString(); if (db.Sessions.Find(sessionId) == null) { Sessions session = new Sessions { Id = sessionId, Date = DateTime.Now }; db.Sessions.Add(session); db.SaveChanges(); } } }
public void OnResultExecuted(ResultExecutedContext filterContext) { using (ApplicationDbContext db = new ApplicationDbContext()) { string url = filterContext.RequestContext.HttpContext.Request.RawUrl.ToString(); string sessionId = filterContext.HttpContext.Session.SessionID.ToString(); Visits visit = new Visits { Date = DateTime.Now, Url = url, Sessions = db.Sessions.Find(sessionId) }; db.Visits.Add(visit); db.SaveChanges(); } }