private void RegisterVisitor() { string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(ipAddress)) { ipAddress = Request.ServerVariables["REMOTE_ADDR"]; } if(ipAddress.Length == 3) { ipAddress = "86.81.102.253"; } string APIKey = "37daa2782cd3c6f1df7e2b511c073b624c3d5ed0c771675985296bfb9aa96ffa"; string url = string.Format("http://api.ipinfodb.com/v3/ip-city/?key={0}&ip={1}&format=json", APIKey, ipAddress); using (WebClient client = new WebClient()) { string json = client.DownloadString(url); Location location = new JavaScriptSerializer().Deserialize<Location>(json); sql_object SqlObj = new sql_object(); SqlObj.addvisitor(location.IPAddress, location.CountryName, location.CountryCode, location.CityName, location.RegionName, location.ZipCode, location.Latitude, location.Longitude, location.TimeZone); Session["visitor"] = location.IPAddress; } }