/// <summary> /// Called by the ASP.NET MVC framework before the action method executes. /// </summary> /// <param name="filterContext">The filter context.</param> public override void OnActionExecuting(ActionExecutingContext filterContext) { ClientInfo clientInfo = Parser.GetDefault().Parse(HttpContext.Current.Request.UserAgent); JSApplicationCookie cookie = GetApplicationCookie(); TrafficLogRequest trafficLogRequest = new TrafficLogRequest() { ApplicationId = (int)SecurityManager.Current.CurrentApplication, Browser = HttpContext.Current.Request.Browser.Browser, BrowserVersion = clientInfo.UserAgent.ToString(), Cookie = cookie.Serialize(SerializationTypes.Json), JSUserId = SecurityManager.Current.UserId, OperatingSystem = clientInfo.OS.ToString(), Device = clientInfo.Device.ToString(), RequestedUrl = HttpContext.Current.Request.RawUrl, RequestType = HttpContext.Current.Request.RequestType, TrackingGuid = SecurityManager.Current.TrackingGuid, TrafficLogGuid = cookie.TrafficLogGuid, UserAgent = HttpContext.Current.Request.UserAgent, UrlReferrer = HttpContext.Current.Request.UrlReferrer == null ? null : HttpContext.Current.Request.UrlReferrer.OriginalString }; string seperator = ""; foreach (string key in HttpContext.Current.Request.Form) { trafficLogRequest.PostedData += String.Format("{0}{1}={2}", seperator, key, HttpContext.Current.Request.Form[key]); seperator = "&"; } IConnectionInfo connectionInfo = SecurityManager.Current.ConnectionInfo; string ipAddress = HttpContext.Current.Request.UserHostAddress; BackgroundProcessHelper.Current.Trigger(async(cancel) => { await SetTrafficLogRequestLocation(trafficLogRequest, ipAddress); await TrafficLogRequestBusinessManager.Current.InsertAsync(connectionInfo, trafficLogRequest); }); base.OnActionExecuting(filterContext); }
private JSApplicationCookie GetApplicationCookie() { JSApplicationCookie cookie = null; if (HttpContext.Current.Request.Cookies[JSCookies.ApplicationCookie] != null) { try { cookie = JSApplicationCookie.Deserialize(HttpContext.Current.Request.Cookies[JSCookies.ApplicationCookie].Value, SerializationTypes.Json); } catch (Exception e) { Task.WhenAll(AppMessenger.Current.Send(MessageTypes.FailedCookieDeserialization, String.Format("{0}: {1}. /r/nCookie Value: {2}", e.GetType().Name, e.Message, HttpContext.Current.Request.Cookies[JSCookies.ApplicationCookie].Value), "Failed to Deserialize the JS Application Cookie", TraceLevels.Error, e.StackTrace)); } if (cookie != null && !String.IsNullOrEmpty(cookie.TrafficLogGuid)) { return(cookie); } else { HttpContext.Current.Response.Cookies.Remove(JSCookies.ApplicationCookie); } } cookie = new JSApplicationCookie() { TrafficLogGuid = Guid.NewGuid().ToString() }; HttpContext.Current.Response.Cookies.Add(new HttpCookie(JSCookies.ApplicationCookie, cookie.Serialize(SerializationTypes.Json))); return(cookie); }