How to detect visitor country

后端 未结 2 1377
谎友^
谎友^ 2021-01-26 17:31

To detect a visitor country I see this below code suggested in many forums, but I cant get it working.

modGlobal.ResolveCountry.ThreeLetterISORegionName<

相关标签:
2条回答
  • 2021-01-26 18:06

    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

    0 讨论(0)
  • 2021-01-26 18:13

    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

    0 讨论(0)
提交回复
热议问题