Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ng Cheong Vee Alan 3 posts 83 karma points
    Oct 26, 2022 @ 11:13
    Ng Cheong Vee Alan
    0

    Localization on cloud

    Hi all,

    Trying to get the clients' location using it's ip address on umbraco cloud using

    Request.UserHostAddress
    

    On a dedicated server it returns the clients' IP. However on Umbraco Cloud, I get a 172.XX.XXX.XXX IP. After I check the IP location for some countries it does provide the right location (Example: Mauritius), but for some it displays the wrong information (Example Reunion)

    Thanks

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Oct 26, 2022 @ 12:53
    Sebastiaan Janssen
    0

    I just want to note here that an IP address is not a reliable way to get someone's country and it really doesn't tell you what language you should show people.

    For me, I am from the Netherlands and speak Dutch and English. I live in Denmark though and get served sites in Danish all the time, even though I have limited understanding of it.

    My browser, however tells the site: hi there, please talk to me in en-US if you can or otherwise nl-NL.

    So all that to say: I would encourage you to look at the accept-language header in the request, instead of finding the possible location of the IP address and forcing a language people don't necessarily want.

  • Ng Cheong Vee Alan 3 posts 83 karma points
    Oct 26, 2022 @ 13:22
    Ng Cheong Vee Alan
    0

    Hi Sebastiaan,

    Thanks for your reply. I am currently trying to capture the location of the client as we are looking to get the country where the user is accessing the website to provide specific offers and rates applicable per destination/country.

    Which is why we installed maxmind geoip on our development server, which was previously cloned from the cloud, and pushed the extension files to Umbraco cloud.

    On our test server, we get the correct location and therefore can provide the correct rates and offers based on where the user is connecting, however while testing on the cloud environment we cannot retrieve the correct IP data for Reunion island. We do however get the correct data for Mauritius.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Oct 26, 2022 @ 14:22
    Sebastiaan Janssen
    0

    Sure, that's a use case I didn't think of. I know that Cloud sites are behind Cloudflare so that probably has something to do with it. I don't know if you can get the end-user's IP address, but worth asking the Cloud support team (us the chat bubble in the Cloud portal - https://umbraco.io/).

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Oct 26, 2022 @ 14:30
    Sebastiaan Janssen
    100

    Looks like you could use the CF-Connecting-IP header to look for the origin IP (I found a hint here: https://our.umbraco.com/documentation/umbraco-cloud/Security/#restrict-backoffice-access-using-ip-filtering) and it looks like this is the answer for any CloudFlare user: https://community.cloudflare.com/t/transform-rule-to-restore-x-forwarded-for/372316/2

  • Ng Cheong Vee Alan 3 posts 83 karma points
    Oct 27, 2022 @ 10:26
    Ng Cheong Vee Alan
    0

    Hi Sebastiaan,

    That works great.

    Changed the Request.UserHostAddress 
    to Request.ServerVariables["HTTP_CF_CONNECTING_IP"];
    

    I can now get client's IP instead of the Proxy.

Please Sign in or register to post replies

Write your reply to:

Draft