Modify the CitiesList file

When creating a new Personalization user segment and specifying a characteristic by Location, Sitefinity provides suggestions for the available options as you type.

AddLocation

All location options that are supported by Sitefinity and are suggested as you type, are stored in the CitiesList.txt file. The files is located under ~/App-Data/GeoLocation and contains a dictionary of City-Region-Country entries, for example: 

Boston      Massachusetts       United States
Town of Boxborough       Massachusetts       United States
Boxford       Massachusetts       United States
..

NOTE: The IpCityLocationService may return none, one, or more than one location matches for a visitor’s IP. Depending on the underlying GeoLocation database the service uses, Sitefinity loads the personalized content only if the location matches the keywords specified in the segment characteristic. In other words, the value coming from the CitiesList.txt is recorded in the database for this personalization segment and is later compared to the location value coming from the IpCityLocationService

To further customize the behavior of Sitefinity personalization module, you can modify the CitiesList.txt in combination with the IpCityLocationService. For example:

Add a new entry to CitiesList.txt

CitiesList.txt is a standard text file, so you can easily update its contents. The contents of CitiesList.txt determine what values Sitefinity displays as autocomplete suggestions as you type your Location characteristic. If you add a new entry to the file, it is displayed by Sitefinity as an autocomplete suggestion as you type. Keep in mind the following:
  • Before adding a new entry, search whether this entry already exists by doing a text search in CitiesList.txt
  • Any new entry you add must meet the City-Region-Country format, as demonstrated above
  • To ensure that the entry you added will work, you need to test whether IpCityLocationService returns a CityLocation with these values. You can do so by calling the GetLocation method of IpCityLocationService with a random IP from the location you want to add to the CitiesList.txt (link to the article/anchor for GetLocation usage)
  • Changes made to CitiesList.txt are automatically picked up by Sitefinity, so you do not need to restart the application

Modify an existing entry in CitiesList.txt

You can modify existing entries to CitiesList to improve accuracy, or simply change the way location suggestions are displayed. For example, you may want to change entries, such as:

London England       United Kingdom

City of London       City of London       United Kingdom

to:

London England       England

City of London       City of London       England

Since the default implementation of IpCityLocationService queries the GeoLite database, the CityLocation returned for a London, UK IP has a value of “United Kingdom” for the  CityLocation.Country property. For your modification to work, you need to extend the IpCityLocationService and specify the criteria, according to which IP matches from UK are returned as England. For more information see Extend or replace the IpCityLocationService

Remove an entry from CitiesList.txt

Removing an entry from the file removes it from the list with autocomplete suggestions. Thus, you control which locations can be selected.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?