public static void LogVisitorInfo(string ip, string rawIp, string appUrl) { var loc = GetIpInfo(ip); Visitor v = new Visitor { VisitTime = DateTime.Now.AddHours(-7), //adjust from Azure UTC url = appUrl, VisitorIpAddress = ip, VisitorRawIp = rawIp }; adhocEntities1 db = new adhocEntities1(); if (loc != null) { v.VisitorIsp = loc.Isp; v.VisitorCity = loc.City; v.VisitorRegion = loc.Region; v.VisitorCountry = loc.Country; v.VisitorPostalCode = loc.PostalCode; v.VisitorLat = loc.Lat; v.VisitorLon = loc.Lon; v.VisitorTimeZone = loc.TimeZone; v.VisitorRawIp = rawIp; v.VisitorName = loc.Name; } db.Visitors.Add(v); db.SaveChanges(); }
public JsonResult Test() { string ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(ip)) ip = Request.ServerVariables["REMOTE_ADDR"]; string rawIp = ip; ip = "70.176.61.73"; if (ip.Contains(':')) { ip = ip.Split(':')[0]; ip = ip.Split(',').Last().Trim(); } string url = Request.Url.GetLeftPart(UriPartial.Authority); var loc = HomepageQueries.GetIpInfo(ip); Visitor v = new Visitor { VisitTime = DateTime.Now.AddHours(-7), //adjust from Azure UTC url = url, VisitorIpAddress = ip, VisitorRawIp = rawIp }; adhocEntities1 db = new adhocEntities1(); if (loc != null) { v.VisitorIsp = loc.Isp; v.VisitorCity = loc.City; v.VisitorRegion = loc.Region; v.VisitorCountry = loc.Country; v.VisitorPostalCode = loc.PostalCode; v.VisitorLat = loc.Lat; v.VisitorLon = loc.Lon; v.VisitorTimeZone = loc.TimeZone; v.VisitorRawIp = rawIp; } return new JsonResult() { Data = JsonConvert.SerializeObject(loc) }; }