ipkenticoip-geolocation

Get Client Ip Kentico 9


I need to get the country of the customer who comes to the site. I can use GeoIPHelper.GetCountryByIp("ip")to get Counry, but how can I get the ip address of the client that comes to the site?


Solution

  • Are you using Kentico EMS? If so then to get country of current contact:

    var countryId = ContactManagementContext.CurrentContact.ContactCountryId;
    var country = CoutryInfoProvider.GetCountryInfo(countryId);
    

    Or

    var currentLocation = GeoIPHelper.GetCurrentGeoLocation();
    

    Which also contains country/state based on current request.