Try our conversational search powered by Generative AI!

Getting enduser current location using Cloudflare

Vote:
 

We want to gend user current user location details like country and region based on IP, by using Cloudflare. And for that we have added below keys in our solution as below:

<add key="episerver:ClientIPAddressHeader" value="True-Client-IP" />

<add key="episerver:ClientLocationHeader" value="CF-IPCountry" />

 But, still are not getting any key in header as  “CF-IPCountry” in browser website. Please help on this

#270328
Jan 21, 2022 11:57
Vote:
 

Hi Rajveer,

Do you have a geolocation provider configured?

Header-based geolocation is only used when no geolocation provider has been configured and that it is limited to Country and Continent locations.

Paul

#270455
Jan 24, 2022 9:39
- Jan 25, 2022 11:02
As per my understanding, with DXP it will come automatically.. and i am using an DXP instance.
And i am not aware about, how geolocation provider is configured.
Vote:
 

Hi Rajveer

I think there is a bit misunderstanding. how do you retrieve the CF-IPCountry? In you controller, do you get any value from this code Request.Headers["CF-IPCountry"]?

#271596
Edited, Feb 12, 2022 0:21
Vote:
 

Hi Rajveer

The configuration entries you mention are only used for location-based Visitor Groups. If you need the country code in custom code, you can use the same implementation as Visitor Groups, by calling:

EPiServer.Personalization.IClientGeolocationResolver.ResolveLocation(HttpContext)

An alternative would be:

Request.Headers["CF-IPCountry"]

Be aware that Cloudflare will only detect the country, not continent, region or city. However, the first method will also give you continent (by internal mapping). Detection needs to be enabled in Cloudflare, so check with Episerver Support whether it is enabled by default.

#271603
Edited, Feb 12, 2022 15:17
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.