Update the GeoIP database for Episerver

  • Updated

Description

The out of the box Geo location API for Episerver uses an old version of the Geo IP database. For some customers, because this is not an updated database, IP addresses show up in the wrong location when personalizing content. There are a few versions of the database that are more accurate but require payment. There is a free option mentioned in a blog post that you can use that is currently maintained. If you run into issues, we would suggest you try this method. Though not supported by our support team, we were able to get it to work internally following the steps below.

Resolution

For CMS 11.6 and newer customers, please see the newest Episerver Maxmind package instead of the below.

  1. Download the code for the Maxmind Geo IP extension from Github.
  2. Open the solution and change the Nuget feed for the Episerver Framework to match your version. 
    There may be dependency issues with your version of Epi and the Newtonsoft.Json requirement so you may need to use a slightly older version of the maxmind database.
  3. Build the solution.
  4. Add a reference in your Epi project to the Pixie.Extensions.Maxmind.GeoIp.dll generated by the build.
  5. Download the GeoLite2 City database to unpack and add the GeoLite2-City.mmdb file to your app_data in your project. 
    The license attribution section on the GeoLite2 database download page that you must add.
  6. Replace the geolocation tags in your web.config with the following (update the location if needed):
    <geolocation defaultProvider="maxmind">
    <providers>
    <add name="maxmind" type="Pixie.Extensions.Maxmind.GeoIp.Provider.MaxmindGeoIp2, Pixie.Extensions.Maxmind.GeoIp" databaseFileName="App_Data\GeoLite2-City.mmdb" />
    </providers>
    </geolocation>
  7. Rebuild your Episerver project
If you build it this way, you will have to update this dll reference when you update your Epi Project to keep them on the same version.

If you'd like to test specific IP addresses against the database, you can use this code snippet. 

Pixie.Extensions.Maxmind.GeoIp.Services.GeolocationMaxmindService service = new Pixie.Extensions.Maxmind.GeoIp.Services.GeolocationMaxmindService();
var ip = System.Net.IPAddress.Parse("1.1.1.1");
var nvc = new System.Collections.Specialized.NameValueCollection();
nvc.Add("databaseFileName", "full path to location of GeoLite2-City.mmdb (Ex C:\\site\\app_data\\GeoLite2-City.mmdb");
var results = service.GetGeoLocation(ip, nvc);