简体   繁体   中英

Get country from which a C# desktop application is run

I WPF/C# desktop application, how to get the country where the user currently is running the application ?

I quess the following just returns the value based on whatever is selected in regional and language options of the Control Panel, therefore making it unusable here.

string countryName = RegionInfo.CurrentRegion.DisplayName;

Found this site for utilizing IP address: http://www.hostip.info/use.html

but this is a corporate application and wondering if used in a corporate VPN therefore possible returning an incorrect country (I want the country where the user is currently sitting physically).

What would be the preferred (most reliable) way to get the country in this setting ?

The way with the regional and language options is imho the right. You also could write something online where u track the public ip adresses and then watch where there are from (but in times with Tor, Proxies, .. it also isnt the best way and u need a connected internet. May we can help u by another way..can u descripe why u want to know the county? greats

You can't reliably do it. Things you can try that can get you closer.

  • Actually ask the user
  • Use regional settings
  • Resolving public IP address
  • Attempt to use GPS, if it is available and you have permissions
  • Attempt to use WiFi (it's probably unlikely in your case as I think this sort of data is private and much guarded)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM