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.
You can use Episerver "GeoLiteCity.dat" file for this. Please refer below articles-
I have gone through those articles. While retrieving ip, it goes to line below.
HttpContext.Current.Request.UserHostAddress;And lookup returns null.
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).
public static class HttpRequestExtensions
public static string GetIpAddress(this HttpRequest request)
string devIpAddress = "18.104.22.168"; // Chicago static public IP
string ipAddress =
ipAddress = request?.ServerVariables["REMOTE_ADDR"];
Try this out and let me know if it helps.
I am not using localhost. GetIpAddress returns local ip and look up returns null.
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?
I wrote about how you can change your local IP for testing purposes using the IIS URL rewrite module here: