Sitefinity Personalization module retrieves geolocation data based on the IP of the visitor currently browsing the site. This enables you to specify different personalization criteria based on visitor location, for example, city, country, and so on.
You can leverage the geolocation service functionality in your custom implementation as well. To do this, you first instantiate the Sitefinity IpCityLocationService. To work with the instance of IpCityLocationService you need to check whether it has successfully loaded the GeoLocation database by using its IsReady property. The IsReady property indicates the service is ready for operation. The property may return false in case you are using the IpCityLocationService too early in your code (for example, in the Global.asax). Thus, you make sure Sitefinity has bootstrapped and read its configurations properly. To use the service in Global.asax, make sure to implement the call to IpCityLocationService in the Bootstrapper_Bootstrapped event handler as demonstrated in the following example:
IpCityLocationService
IsReady
Global.asax
Bootstrapper_Bootstrapped
Once you verify the service is ready, you call its GetLocation method by passing an IPAddress parameter. If a match is found for the specified IP address, IpCityLocationService returns a CityLocation object that contains the City, Country, ISO Code, Region, PostalCode, geographic coordinates of the matched location. Refer to the sample below on how to use IpCityLocationService in your code:
GetLocation
IPAddress
CityLocation
Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.
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.
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.
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.
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important