November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi Muller,
You can use Episerver "GeoLiteCity.dat" file for this. Please refer below articles-
Thanks
Ravindra
I have gone through those articles. While retrieving ip, it goes to line below.
HttpContext.Current.Request.UserHostAddress;
And lookup returns null.
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
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:
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.