public static string FindSearchKeywords(this IWebRequestLog log)
        {
            if (log.UrlReferer.IsEmpty())
            {
                return(null);
            }

            // var url = UrlReferer.ToLower();

            if (!log.UrlReferer.ToLower().Contains(".google.co"))
            {
                return(null);
            }

            foreach (var possibleQuerystringKey in new[] { "q", "as_q" })
            {
                var query = new Uri(log.UrlReferer).Query.TrimStart("?").OrEmpty().Split('&').Trim().FirstOrDefault(p => p.StartsWith(possibleQuerystringKey + "="));

                if (query.HasValue())
                {
                    return(HttpUtility.UrlDecode(query.Substring(1 + possibleQuerystringKey.Length)));
                }
            }

            return(log.UrlReferer);
        }
Exemple #2
0
 public static int CountSessionRequests(this IWebRequestLog request)
 {
     if (request.SessionId.IsEmpty())
     {
         return(1);
     }
     return(Database.Count <IWebRequestLog>(x => x.SessionId == request.SessionId));
 }
 public static async Task <int> CountSessionRequests(this IWebRequestLog request)
 {
     if (request.SessionId.IsEmpty())
     {
         return(1);
     }
     return(await Entity.Database.Count <IWebRequestLog>(x => x.SessionId == request.SessionId));
 }
Exemple #4
0
        public static string GetLastVisitedUrl(this IWebRequestLog request)
        {
            if (request.SessionId.IsEmpty())
            {
                return(request.Url);
            }

            return(Database.GetList <IWebRequestLog>(x => x.SessionId == request.SessionId).WithMax(x => x.Start)?.Url);
        }
        public static async Task <string> GetLastVisitedUrl(this IWebRequestLog request)
        {
            if (request.SessionId.IsEmpty())
            {
                return(request.Url);
            }

            return((await Entity.Database.GetList <IWebRequestLog>(x => x.SessionId == request.SessionId)).WithMax(x => x.Start)?.Url);
        }
 /// <summary>
 /// Records this web request log in the provided http context.
 /// </summary>
 public static void Record(this IWebRequestLog log, HttpContext context)
 {
     try
     {
         DoRecord(log, context);
     }
     catch (Exception ex)
     {
         Log.Error("Could not record Web Request Log", ex);
     }
 }
        /// <summary>
        /// Gets the value of a query string key.
        /// </summary>
        public static string GetData(this IWebRequestLog log, string key)
        {
            var query = new Uri(log.Url).Query?.TrimStart("?").Split('&').FirstOrDefault(p => p.StartsWith(key + "="));

            if (query.IsEmpty())
            {
                return(null);
            }
            else
            {
                return(HttpUtility.UrlDecode(query.Substring(1 + key.Length)));
            }
        }
        static async Task DoRecord(IWebRequestLog log, HttpContext context)
        {
            log.ProcessingTime = LocalTime.Now.Subtract(log.Start).TotalMilliseconds;

            log.Url         = context.Request.ToRawUrl();
            log.UserAgent   = context.Request.Headers["User-Agent"].ToString();
            log.IP          = context.Connection.RemoteIpAddress.ToString();
            log.RequestType = context.Request.Method;
            log.UrlReferer  = context.Request.Headers["Referer"].ToString();
            log.SessionId   = context.Session?.Id;

            if (context.Response.ContentLength.HasValue)
            {
                log.ResponseLength = (int)(context.Response.ContentLength.Value / 1024);
            }

            await Entity.Database.Save(log);
        }
        static void DoRecord(IWebRequestLog log, HttpContext context)
        {
            if (!(context.Handler is Page) && context.Handler?.GetType().Name != "MvcHandler")
            {
                return;
            }

            log.ProcessingTime = LocalTime.Now.Subtract(log.Start).TotalMilliseconds;

            log.Url         = context.Request.Url.ToString();
            log.UserAgent   = context.Request.UserAgent;
            log.IP          = context.Request.UserHostAddress;
            log.RequestType = context.Request.RequestType;
            log.UrlReferer  = context.Request.UrlReferrer?.ToString();
            log.SessionId   = context.Session?.SessionID;

            try
            {
                log.ResponseLength = (int)context.Response.OutputStream.Length / 1024;
            }
            catch { }

            Database.Save(log);
        }
Exemple #10
0
 public static bool IsBouncedBack(this IWebRequestLog request)
 {
     return(request.CountSessionRequests() == 1);
 }
Exemple #11
0
 public static TimeSpan GetDuration(this IWebRequestLog request)
 {
     return(TimeSpan.FromMilliseconds(request.ProcessingTime));
 }
 /// <summary>
 /// Gest the last url visited in this session.
 /// </summary>
 public static string GetLastVisitedUrl(this IWebRequestLog log)
 {
     return(Database.GetList <IWebRequestLog>(r => r.SessionId == log.SessionId).WithMax(r => r.Start).Url);
 }
 /// <summary>
 /// Gets the number of requests made in the same session.
 /// </summary>
 public static int CountRequestsInSession(this IWebRequestLog log)
 {
     return(Database.Count <IWebRequestLog>(r => r.SessionId == log.SessionId));
 }
 /// <summary>
 /// Gest the last url visited in this session.
 /// </summary>
 public static async Task <string> GetLastVisitedUrl(this IWebRequestLog log)
 {
     return((await Entity.Database.GetList <IWebRequestLog>(r => r.SessionId == log.SessionId)).WithMax(r => r.Start).Url);
 }
 /// <summary>
 /// Gets the number of requests made in the same session.
 /// </summary>
 public static async Task <int> CountRequestsInSession(this IWebRequestLog log) =>
 await Entity.Database.Count <IWebRequestLog>(r => r.SessionId == log.SessionId);
 public static async Task <bool> IsBouncedBack(this IWebRequestLog request) => await request.CountSessionRequests() == 1;