예제 #1
0
        private void Location()
        {
            // Full path to GeoLiteCity.dat file
            string FullDBPath = Server.MapPath("App_Data/GeoLiteCity.dat");
            // Visitor's IP address
            string VisitorIP = Request.ServerVariables["REMOTE_ADDR"];

            // Create objects needed for geo targeting
            Geotargeting.LookupService ls = new Geotargeting.LookupService(FullDBPath, Geotargeting.LookupService.GEOIP_STANDARD);
            Geotargeting.Location      visitorLocation = ls.getLocation(VisitorIP);

            // Get geo targeting data
            Response.Write("Your IP Address: " + VisitorIP + "<br />");
            Response.Write("Your country: " + visitorLocation.countryName + "<br />");
            Response.Write("Your country code: " + visitorLocation.countryCode + "<br />");
            Response.Write("Your region: " + visitorLocation.region + "<br />");
            Response.Write("Your city: " + visitorLocation.city + "<br />");
            Response.Write("Your postal code: " + visitorLocation.postalCode + "<br />");
            Response.Write("Area code: " + visitorLocation.area_code + "<br />");
            Response.Write("dma: " + visitorLocation.dma_code + "<br />");
            Response.Write("Latitude: " + visitorLocation.latitude + "<br />");
            Response.Write("Longitude: " + visitorLocation.longitude + "<br />");
        }
예제 #2
0
    public static void UpdateImpression(string adId, int type)
    {
        try
        {
            // Full path to GeoLiteCity.dat file
            string fullDBPath = HttpContext.Current.Server.MapPath("~/App_Data/GeoLiteCity.dat");

            // Visitor's IP address
            string visitorIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

            // Create objects needed for geo targeting
            var ls = new Geotargeting.LookupService(fullDBPath, Geotargeting.LookupService.GEOIP_STANDARD);

            //Geotargeting.Location visitorLocation = ls.getLocation(VisitorIP);
            //testing
            var visitorLocation = ls.getLocation("68.70.88.2");

            var myWebVisitor = new WebsiteVisitor(HttpContext.Current);

            //YOU Need to account for NULL AND FOR LOWER CASE!!!!!!!!!!!!!!///////////////
            //YOU Need to account for NULL AND FOR LOWER CASE!!!!!!!!!!!!!!///////////////

            int countryID;
            int regionID;
            int cityID;
            using (var context = new SidejobEntities())
            {
                try
                {
                    var selectedCountryID =
                        from c in context.CountriesUpdates
                        where c.ISO2 == visitorLocation.countryCode
                        select c.CountryId;

                    countryID = selectedCountryID.FirstOrDefault();
                    if (countryID == 0)
                    {
                        //Default: US
                        countryID = 254;
                    }

                    var selectedRegionID =
                        from c in context.regionsUpdates
                        where c.Code == visitorLocation.region && c.CountryId == Convert.ToInt32(selectedCountryID)
                        select c.RegionId;
                    regionID = Convert.ToInt32(selectedRegionID);
                    if (regionID == 0)
                    {
                        //Default: NY
                        regionID = 154;
                    }

                    var selectedCityID =
                        from c in context.CitiesUpdates
                        where c.City == visitorLocation.city
                        select c.CityId;
                    cityID = Convert.ToInt32(selectedCityID);
                    if (cityID == 0)
                    {
                        //Default: NY
                        cityID = 10182;
                    }
                }
                catch (Exception)
                {
                    //Default: US
                    countryID = 254;

                    //Default: NY
                    regionID = 154;

                    //Default: NY
                    cityID = 10182;
                }
            }

            ///////////////
            string refURL = "Exception";
            ///////////////

            ScheduleImpressionUtility.UpdateImpression(Convert.ToInt32(adId),
                                               Convert.ToDateTime(
                                                   DateTime.Today.ToString(
                                                       CultureInfo.InvariantCulture)),
                                               type, visitorIP, visitorLocation.countryCode,
                                               visitorLocation.region,
                                               visitorLocation.postalCode,
                                               visitorLocation.area_code, visitorLocation.dma_code,
                                               visitorLocation.latitude,
                                               visitorLocation.longitude,
                                               refURL, myWebVisitor.BrowserType,
                                               myWebVisitor.BrowserName,
                                               myWebVisitor.BrowserPlatform,
                                               myWebVisitor.UserHostAddress,
                                               myWebVisitor.UserHostName,
                                               myWebVisitor.UserLanguages,
                                               myWebVisitor.MobileDeviceManufacturer,
                                               myWebVisitor.MobileDeviceModel,
                                               myWebVisitor.DeviceType,
                                               100, "PRO", "haithem", "smith", "address", countryID,
                                               visitorLocation.countryCode,
                                               regionID, visitorLocation.region, cityID,
                                               visitorLocation.city,
                                               "91340605", 28, 1,
                                               "emailAddress", "photoPath", 5, 52, 1);

            //// UpdateImpression(int adId, DateTime entryData, int type, string iPAddress, string countryCode, string region, string postalcode,
            //int areaCode, int metroCode, double latiture, double longitude, string refURL, string browserType, string browserName, string browserPlatform,  string userHostAddress,
            //string userHostName,
            //string userLanguage,string mobileDeviceManufacturer,
            // string mobileDeviceModel, string deviceType,  int userId, string userRole, string firstName,
            //string lastName, string address, int countryID, string countryName, int regionID,
            //string regionName, int cityID, string cityName, string phone, int age, int gender,
            //string emailAddress, string photoPath, int industryID, int professionID, int lcid)
        }
        catch (Exception)
        {
        }
    }
예제 #3
0
    public static UserMachineLocation GetInfo()
    {
        try
        {
            // Full path to GeoLiteCity.dat file
            string fullDBPath = HttpContext.Current.Server.MapPath("~/App_Data/GeoLiteCity.dat");

            // Visitor's IP address
            string visitorIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

            // Create objects needed for geo targeting
            var ls = new Geotargeting.LookupService(fullDBPath, Geotargeting.LookupService.GEOIP_STANDARD);

            Geotargeting.Location visitorLocation = ls.getLocation(visitorIP);
            //testing
            //var visitorLocation = ls.getLocation("68.70.88.2");

            var myWebVisitor = new WebsiteVisitor(HttpContext.Current);

            //YOU Need to account for NULL AND FOR LOWER CASE!!!!!!!!!!!!!!///////////////
            //YOU Need to account for NULL AND FOR LOWER CASE!!!!!!!!!!!!!!///////////////

            int countryID;
            int regionID;
            int cityID;
            using (var context = new SidejobEntities())
            {
                try
                {
                    var selectedCountryID =
                        from c in context.CountriesUpdates
                        where c.ISO2 == visitorLocation.countryCode
                        select c.CountryId;

                    countryID = selectedCountryID.FirstOrDefault();
                    if (countryID == 0)
                    {
                        //Default: US
                        countryID = 254;
                    }

                    var selectedRegionID =
                        from c in context.regionsUpdates
                        where c.Code == visitorLocation.region && c.CountryId == Convert.ToInt32(selectedCountryID)
                        select c.RegionId;
                    regionID = Convert.ToInt32(selectedRegionID);
                    if (regionID == 0)
                    {
                        //Default: NY
                        regionID = 154;
                    }

                    var c1 = from c in context.CitiesUpdates
                             where c.City == visitorLocation.city
                             select c;
                    var city = "";
                    cityID = 10182;
                    var c2 = c1.FirstOrDefault();
                    if (c2 != null)
                    {
                        var selectedCityID = c2.CityId;
                        cityID = Convert.ToInt32(selectedCityID);
                        city = c2.City;
                    }
                    if (cityID == 0)
                    {
                        //Default: NY
                        cityID = 10182;
                    }
                    return new UserMachineLocation(countryID, regionID, cityID, GetZipcode(countryID, regionID,city,visitorLocation.postalCode));
                }
                catch (Exception)
                {
                    //Default: US
                    countryID = 254;

                    //Default: NY
                    regionID = 154;

                    //Default: NY
                    cityID = 10182;

                    //Defauly Zipcode
                    //10185 : NY NY

                    return new UserMachineLocation(254, 154, 10182, "10185");

                }
            }
        }
        catch (Exception)
        {
            return new UserMachineLocation(254, 154, 10182, "10185");
        }
    }