EPiServer CMS 6 R2 comes with the great new personalisation feature of Visitor Groups. One of the criterion's available to personalise on is the “geographic location” criteria. Put simply this allows editors to specify a location and/or country to personalise content.

Obviously this functionality utilises a Geo/IP lookup database under the hood. The provider is specified in the EPiServerFramework.config file as follows (in R2 Beta):

<geolocation defaultProvider="maxmind">
    <add databaseFileName="C:\Program Files\EPiServer\Framework\\Geolocation\GeoLiteCity.dat"
      name="maxmind" type="EPiServer.Personalization.Providers.MaxMind.GeolocationProvider, EPiServer.ApplicationModules" />

I wanted to find a way to use this feature in my own code for use in reporting or possibly in something like a gadget. Allan Thræn had mentioned that it would be available through the EPiServer API so I decided to investigate. It turns out to be remarkably simple:

GeolocationProvider prov = EPiServer.Personalization.Geolocation.Provider as GeolocationProvider;
IPAddress ip = IPAddress.Parse("");
IGeolocationResult result = prov.Lookup(ip);

This code is also available on the EPiServer code section.