Reputation: 14468
To detect a visitor country I see this below code suggested in many forums, but I cant get it working.
modGlobal.ResolveCountry.ThreeLetterISORegionName
On my local machine it correctly return my computer retional settings region whereas it on the production server always return USA.
I guess this is because the function return the envoirement regional settings (ie the servers regional setting), can anyone confirm this? And if true, what is best practice for detecting visitors country in asp.net?
Upvotes: 0
Views: 4846
Reputation: 15387
Try this
Dictionary<string,string> objDic = new Dictionary<string,string>();
foreach (CultureInfo ObjCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo objRegionInfo = new RegionInfo(ObjCultureInfo.Name);
if (!objDic.ContainsKey(objRegionInfo.EnglishName))
{
objDic.Add(objRegionInfo.EnglishName, objRegionInfo.TwoLetterISORegionName.ToLower());
}
}
var obj = objDic.OrderBy(p => p.Key );
foreach (KeyValuePair<string,string> val in obj)
{
ddlCountries.Items.Add(new ListItem(val.Key, val.Value));
}
EnglishName
will return country name
From the IP see
Upvotes: 1
Reputation: 363
Try to get the ip from the visitor and look up the trace data from it
Maybe have a look at this: How to get visitor location ( country, state and city ) using ASP.NET
Upvotes: 0