Exemplo n.º 1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);

            try
            {
                var visit = new Models.Visit()
                {
                    StartTime = DateTime.UtcNow,
                    IpAddress = filterContext.HttpContext.Request.UserHostAddress,
                    Website   = Website,
                    Location  = filterContext.HttpContext.Request.RawUrl,
                    UserAgent = filterContext.HttpContext.Request.UserAgent,
                    Referrer  = (null != filterContext.HttpContext.Request.UrlReferrer) ? filterContext.HttpContext.Request.UrlReferrer.AbsoluteUri : null
                };

                db = new Database.AnalyticsDb(NameOrConnectionString);
                db.Analytics_Visits.Add(visit);
                db.SaveChanges();

                VisitId = visit.Id;
            }
            catch (Exception ex)
            {
                LogError(ex);
            }
        }
Exemplo n.º 2
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);

            try
            {
                if (null != VisitId)
                {
                    var visit = db.Analytics_Visits.Find(VisitId);
                    visit.EndTime = DateTime.UtcNow;
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                LogError(ex);
            }
        }