This may help your question on 1.
This may also help if you want to use an alternative header for IP addresses:
The GeolocationProvider returns null in your case because the address is IPv6 address and it only supports IPv4 addresses.
If you enable debug logging and log messages from EPiServer.Personalization.Providers.MaxMind -namespace you can see in the logs message about IPv4 only supported.
Thanks guys - both suggestions helped but now I'm confused about what is generating the path to the GeoLiteCity.dat file.
My GeoLiteCity.dat file sits here: ~/App_Data/GeoLiteCity.dat but whenever this runs:
It errors saying cant find file ~/GeoLiteCity.dat <--- missing App_Data/
What is creating the path to this file?
Update: adding web.xml config
<geolocation defaultProvider="maxmind"> <providers> <add name="maxmind" type="EPiServer.Personalization.Providers.MaxMind.GeolocationProvider, EPiServer.ApplicationModules" databaseFileName="App_Data\GeoLiteCity.dat" /> </providers> </geolocation>
Sorry been busy with work so I was not able to answer to you sooner.
You are using deprecated way of getting the GeolocationProvider (you haven't mentioned which version of Episerver packets you are using) but I did a quick test with Alloy using version 11.5.0 (EPiServer.CMS package).
The GeolocationProvider is registered to the IoC container so you should get it from there. You can use the normal ways of Episerver to get the service injected to your controllers for example (in the constructor like: EPiServer.Personalization.IGeolocationProvider geolocationProviderBase) but in your case you might use the Servicelocator like this: ServiceLocator.Current.GetInstance<IGeolocationProvider>();
So something like this should work for you:
// add usings using EPiServer.ServiceLocation; using EPiServer.Personalization; // code var provider = ServiceLocator.Current.GetInstance<IGeolocationProvider>(); // naturally replace the IP parsing with your code IGeolocationResult result = provider.Lookup(System.Net.IPAddress.Parse("xxx.xxx.xxx.xxx")); // and then use the result
Or you could use the Injected property in your criteria if you prefer that over ServiceLocator, https://world.episerver.com/documentation/Class-library/?documentId=cms/11/1692DF76
(as a side note your config values are defaults and look ok)
Hi Antti - thanks for the reply.
Unfortunately I'm still getting null back as my result.
Im using ServiceLocator to get the instance of IGeolocationProvider, but whenever I call the LookUp( ) action, it always retruns null.
var provider = ServiceLocator.Current.GetInstance<IGeolocationProvider>(); var result = provider.Lookup(IPAddress.Parse("xxx.xxx.xxx.xxx"));
When a breakpoint is added and I hover over provider I see:
and when expanded I see properties for "Capabilities" which as a value of 0 and "Name" which has a value of 'default'.
ERROR EPiServer.Personalization.Providers.MaxMind.GeolocationProvider: Geolocation database file cannot be found: C:\Users\<user>\Source\Repos\<myproject>\<myprojcet>\GeoLiteCity.dat ERROR EPiServer.Personalization.Providers.MaxMind.GeolocationProvider: Error occured while looking up xxx.xxx.xxx.xxx : Path cannot be null.
So, right off the bat it's still not looking in the right spot, it should be looking in <myproject>/App_Data/.
Seems like its not using the 'databaseFileName' property from web.config
Thanks again for the assistance,
While the path is very similar to yours I'm thinking that it's more likely that the provider uses the default database path, which happens to be "GeoLiteCity.dat". If this is the case it looks like it's completely disregarding your configuration for some reason. You should be able to confirm this by either changing the path in the web.config to something completely different or even go as far as removing the geolocation provider completely. If this is the case, could it be something simple such as the <geolocation> element is defined outside the <episerver.framework> section or similar?
I commented out the whole <geolocation> tag and it gave me the same exact result as before.
When I try moving <geolocation> outside of <episerver.framework> the project refuses to build.
When I move the GeoLiteCity.dat file to the spot it is already looking the errors stop, though I get the same result ( GeoLocationProvider comes through, LookUp( ) returns null )
Assuming the GeoLocationProvider does pull its config from web.config - I would agree it seems to be ignoring this file/config.
I am thoroughly stumped.
IGeolocationResult result = ServiceLocator.Current.GetInstance<IGeolocationProvider>().Lookup(IPAddress.Parse("xxx.xxx.xxx.xxx"));
plugged that ^^ into Alloy and result came back as null there too - not sure whats going on here.
Ive created a new Criterion Class and am looking to restrict content by region.
This is the criterion class
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 ):