Ejemplo n.º 1
0
        public async Task OnActionExecutionAsync(
            ActionExecutingContext context,
            ActionExecutionDelegate next)
        {
            // Do something before the action executes.
            var userAgent = context.HttpContext?.Request?.Headers["User-Agent"].ToString();
            var userIp    = context.HttpContext?.Connection?.RemoteIpAddress?.ToString();

            var userOs      = VisitorsStatisticsHelper.GetUserOsName(userAgent);
            var browserName = VisitorsStatisticsHelper.GetUserBrowserName(userAgent);
            var deviceName  = VisitorsStatisticsHelper.GetUserDeviceName(userAgent);

            //var url = Url.Action("Index", "Home", null, ViewContext.HttpContext.Request.Scheme);

            var getIp = _httpRequestInfoService.GetIP();

            var getHeaderValue = _httpRequestInfoService.GetHeaderValue("Accept-Language");

            var getUserAgent = _httpRequestInfoService.GetUserAgent();

            var absoluteContent  = _httpRequestInfoService.AbsoluteContent("~/");
            var absoluteContent2 = _httpRequestInfoService.AbsoluteContent(context.HttpContext?.Request?.Path.Value ?? "~/");

            var getBaseUrl = _httpRequestInfoService.GetBaseUrl();

            var getRawUrl = _httpRequestInfoService.GetRawUrl();

            //var getUrlTitleAsync = await _htmlHelperService.GetUrlTitleAsync(context.HttpContext?.Request?.Path.Value ?? "~/");

            var getUrlHelper = _httpRequestInfoService.GetUrlHelper().Content(context.HttpContext?.Request?.Path.Value ?? "~/");

            var viewModel = new VisitorsStatisticsViewModel()
            {
                UserAgent   = userAgent,
                UserOs      = userOs.ToString(),
                BrowserName = browserName.ToString(),
                DeviceName  = deviceName.ToString(),
                IpAddress   = userIp,
                PageViewed  = null,
                VisitDate   = DateTimeOffset.UtcNow,
            };

            await _statService.InsertAsync(viewModel);

            // next() calls the action method.
            var resultContext = await next();

            // resultContext.Result is set.
            // Do something after the action executes.
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            var totalVisits = await _visitorsStatisticsService.GetTotalVisitsAsync();

            var ip        = _httpRequestInfoService.GetIP();
            var userAgent = _httpRequestInfoService.GetHeaderValue("User-Agent");

            var userOs      = VisitorsStatisticsHelper.GetUserOsName(userAgent);
            var browserName = VisitorsStatisticsHelper.GetUserBrowserName(userAgent);
            var deviceName  = VisitorsStatisticsHelper.GetUserDeviceName(userAgent);

            var viewModel = new CurrentVisitorViewModel()
            {
                Browser     = browserName.ToString(),
                BrowserIcon = browserName.Family.ToLowerInvariant(),
                IpAddress   = ip,
                CountryName = "",
                OsName      = userOs.ToString(),
                OsIcon      = userOs.Family.ToLowerInvariant(),
                TotalVisits = totalVisits,
            };

            return(View(viewModel));
        }