Home
> Uncategorized > Get #ISO3166 Country code from #IP address in C#
Get #ISO3166 Country code from #IP address in C#
Although an IP address can’t always pinpoint where a user is to the correct city, it’s pretty reliable way of getting the user’s country, and you can tailor the content for that user, i.e. show prices in GBP for UK users, and USD for USD users.
There are plenty of ways of doing this, and many services that provide this service, but this worked well for me in an ASP.NET MVC website
WebClient wc = new WebClient();
var strJson = wc.DownloadString(“http://ipinfo.io/” + Request.ServerVariables[“REMOTE_ADDR”]);
var ip = Newtonsoft.Json.Linq.JObject.Parse(strJson);
var country = ip[“country”].ToString();
Categories: Uncategorized
Comments (0)
Trackbacks (0)
Leave a comment
Trackback