November Happy Hour will be moved to Thursday December 5th.

Open site of particular language depending upon location

Vote:
 


I have site with languages en-gb, en-za and master language en-us. However, I want en-gb as default language and en-gb should be opened when the site is opened from all countries other than Uk (en-gb) and South Africa (en-za); en-gb and en-za site should be opened only when they are browsed from the respective countries. Also, if the site is opened without entering language it should go to default language.

#207179
Sep 12, 2019 5:34
Vote:
 

I have gone through those articles. While retrieving ip, it goes to line below.

HttpContext.Current.Request.UserHostAddress;

And lookup returns null.
#207252
Sep 16, 2019 4:50
Vote:
 

Hi Muller,

That's may be due to testing on local. Which has a local loopback ip address (127.0.0.1). You can test with hard code the ip and can test with different country ip addresses. See below code example. After hosting the application it will work as expected (if not using the proxy, of course).

using System.Linq;
using System.Web;
using System.Web.Hosting;

public static class HttpRequestExtensions
{
    public static string GetIpAddress(this HttpRequest request)
    {
        if (HostingEnvironment.IsDevelopmentEnvironment)
        {
            string devIpAddress = "XXX.XXX.XXX.XXX"; // Your IP address
            return devIpAddress;
        }

        string ipAddress =
            request
                ?.ServerVariables["HTTP_X_FORWARDED_FOR"]
                ?.Split(',')
                .ToList()
                .FirstOrDefault();

        if (string.IsNullOrWhiteSpace(ipAddress))
        {
            ipAddress = request?.ServerVariables["REMOTE_ADDR"];
        }

        return ipAddress;
    }
}

Try this out and let me know if it helps.

Thanks

#207313
Edited, Sep 17, 2019 8:37
Vote:
 

I am not using localhost. GetIpAddress returns local ip and look up returns null.

#207332
Sep 17, 2019 10:28
Praful Jangid - Sep 17, 2019 10:43
What is your local ip?
Vote:
 

That's what I am saying. Your local ip is not in the database of maxmind that handles the IP lookup. So on your local machine it will return the loopback ip and it will not find your location based on that ip. So try with passing ip from any country ip range. You can do Google for ip range of any country. Pass it as shown in code example above.

You are using maxmind, right?

#207334
Sep 17, 2019 10:38
Muller - Sep 17, 2019 14:42
I have hosted site. Yes I am using maxmind. How can I get resolve my public ip instead of local one? ServerVariables["HTTP_X_FORWARDED_FOR"] does not return value.
Praful Jangid - Sep 17, 2019 15:08
Actually local running site (even hosted in IIS) will always give the loopback ip address. So you can either pass ip in code or you can follow the David's blog post to configure it in iis.
Muller - Sep 17, 2019 15:13
By "Pass ip in code" , do you mean your code? I did. If you read above again, I have mentioned that. It returns local ip.
Praful Jangid - Sep 17, 2019 15:17
So, as you are saying, your site is hosted in iis on local machine then you can try Devid's post.
Vote:
 

I wrote about how you can change your local IP for testing purposes using the IIS URL rewrite module here:

https://www.david-tec.com/2011/06/Using-the-IIS-rewrite-module-to-test-EPiServer-geo-IP-look-up-personalisation/ 

#207346
Sep 17, 2019 14:35
Vote:
 

https://world.episerver.com/blogs/Henrik-Nystrom/Dates/2018/6/geolocation-provider-changes/

#207376
Sep 17, 2019 19:08
* 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.