0

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?

Muleskinner
  • 14,150
  • 19
  • 58
  • 79

2 Answers2

1

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

Amit
  • 15,217
  • 8
  • 46
  • 68
0

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

Community
  • 1
  • 1
Danny.
  • 363
  • 1
  • 4
  • 23