예제 #1
0
        public ActionResult Resolution(int height, int width)
        {
            // collecting and storing the browser and resolution
            BrowserResolution record = new BrowserResolution()
            {
                BrowserResolutionHeight = height.ToString(),
                BrowserResolutionWidth = width.ToString(),
                IPAddress = Request.UserHostAddress,
                Browser = Request.Browser.Browser
            };

            // save the record to the tracking table.
            VisitorStatisticsContext context = new VisitorStatisticsContext();
            context.BrowserResolutionRecord.Add(record);
            context.SaveChanges();

            return new HttpStatusCodeResult(HttpStatusCode.OK);
        }
예제 #2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            // store the request in an accessible object
            var request = filterContext.HttpContext.Request;
            //generate a visitor statistic record.
            VisitorStatistic visitor = new VisitorStatistic()
            {
                UserName = (request.IsAuthenticated) ? filterContext.HttpContext.User.Identity.Name : "Annonymous",
                IPAddress = request.UserHostAddress ?? request.ServerVariables["HTTP_X_FORWARDED_FOR"],
                AlternateIPAddress = request.ServerVariables["REMOTE_ADDR"] ?? "Not Available",
                AreaAccessed = request.RawUrl,
                Timestamp = DateTime.UtcNow,
                Referer = request.ServerVariables["HTTP_REFERER"] ?? "internet",
                Browser = request.Browser.Browser
            };
            // stores the tracked info in the database
            VisitorStatisticsContext context = new VisitorStatisticsContext();
            context.VisitorStatisticRecords.Add(visitor);
            context.SaveChanges();

            //finished executing the action as normal
            base.OnActionExecuting(filterContext);
        }
예제 #3
0
 /// <summary>
 /// Inject neccessary dependencies.
 /// </summary>
 /// <param name="db"></param>
 public AdminController(VisitorStatisticsContext db, IWritableOptions <AppSettings> appSettings, IConfiguration config)
 {
     _db          = db;
     _appSettings = appSettings;
     _config      = config;
 }
 public VisitorHandler(VisitorStatisticsContext db, IHttpContextAccessor context)
 {
     _db      = db;
     _context = context;
 }
예제 #5
0
 public ActionResult ViewBrowserStats()
 {
     var stats = new VisitorStatisticsContext().BrowserResolutionRecord;
     return View(stats);
 }
예제 #6
0
 public ActionResult ViewVisitorStats()
 {
     var stats = new VisitorStatisticsContext().VisitorStatisticRecords;
     return View(stats);
 }
 public HomeController(VisitorStatisticsContext db)
 {
     _db = db;
 }