Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

Issue w/ GeoLocation

$
0
0

Ive created a new Criterion Class and am looking to restrict content by region. 

This is the criterion class

[VisitorGroupCriterion(DisplayName = "Region Only!")]
    public class RegionCriterion : CriterionBase
    {
        public override bool IsMatch(IPrincipal principal, HttpContextBase httpContext)
        {
            string usersIP = null;
            if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                usersIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else
            {
                usersIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            var geoLocationProvider = Geolocation.Provider as GeolocationProvider;
            IPAddress address = IPAddress.Parse("usersIP");
            IGeolocationResult result = geoLocationProvider.Lookup(address);
            return (result.Region.Equals("myRegion")); ;
        }
    }

2 issues here.

First} Due to my setup my ip always comes back as ::1. Is there a way i can get around this for testing without hardcoding the ip address?

Second} result always returns null w/o error and I cant figure out why.

Ive followd the directions from here but still dont have a working set up ( I have the latest db and am able to run the update command successfully ):
https://world.episerver.com/documentation/developer-guides/CMS/personalization/Configuring-personalization/


Any thoughts?

CC


Viewing all articles
Browse latest Browse all 9076

Trending Articles