Implement IpCityLocationService

To extend the default functionality of Sitefinity IpCityLocationService, you can implement the IIpCityLocationService interface in your class. You then replace the instance of IpCityLocationService that Sitefinity uses with your implementation via the ObjectFactory container.  The IIpCityLocationService interface requires you to implement the GetLocation(IPAddress ipAddress) method and the bool IsReady  property. 

Extend the service

To extend the default functionality, you can call the Sitefinity base implementation and plug your logic afterwards. For example:

Next, you register the newly created service in Global.asax as follows:


Replace the default service

Sitefinity implementation of IpCityLocationService relies on the MaxMind GeoLite2 database. To change this logic completely and use a different GeoLocation database, you can implement the IIpCityLocationService interface with your own logic and register the service.

The following example demonstrates how to implement the IIpCityLocationService with the previous version of the MaxMind GeoLite City database and API.

NOTE: The database and API versions of MaxMind GeoLite, mentioned above are used by Sitefinity CMS versions 11.0 and older. In case you notice discrepancies in the behavior between the old database and the new one used in Sitefinity 11.1 and newer, you can use this sample to achieve backward compatibility. In addition, you can use this sample to get you started on how IIpCityLocationService interface can be implemented for any other geo IP database service and used in Sitefinity. 

  1. Install the MaxMind GeoIP API, available as a NuGet package in the following location:
  2. Download the MaxMind GeoLite City database. MaxMind still has the old databases available for download at You need to download the binary (e.g. and extract it in your Sitefinity website ~/App_Data/GeoLocation/ folder. The extracted file name must be GeoLiteCity.dat.
  3. Implement the IIpCityLocationService. When implementing IIpCityLocationService interface in your custom service, you need to:
    1. Implement the IsReady property so it indicates to Sitefinity or your custom code whether the service is ready to be used. This sample demonstrates how IsReady can be set to true/false by checking whether the MaxMind LookupService object is properly instantiated.
    2. Implement the GetLocation method, so that your service can return CityLocation objects. This sample uses the MaxMind LookupService public  getLocation(IPAddress addr) method and populates a Sitefinity CityLocation object with the result.

    The complete sample follows:

  4. Replace the default IpCityLocationService used by Sitefinity with your custom one. To do that you need to hook up to the Bootstrapper.Bootstrapped event in your Sitefinity application’s Global.asax and register your service through the ObjectFactory container:

Want to learn more?

Sign up for our free beginner training. Boost your credentials through advanced courses and certification.
Register for Sitefinity training and certification.

Was this article helpful?