Try our conversational search powered by Generative AI!

Open site of particular language depending upon location


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.

Sep 12, 2019 5:34

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


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

Hi Muller,

That's may be due to testing on local. Which has a local loopback ip address ( 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 =

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

        return ipAddress;

Try this out and let me know if it helps.


Edited, Sep 17, 2019 8:37

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

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

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?

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.

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

Sep 17, 2019 14:35

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.