hmk hmk - 1 year ago 91
ASP.NET (C#) Question

using ASP.NET to display the visitor location like country, state and city in master page

How to get visitor location like country, state and city using ASP.NET, i saw some examples All are based on IP Address to get the Details(based on some free services), now my problem is above example that services only working registered Ip addresses, but now my task is when user browse the my website, display the Country, state and city how it possible, please give me any suggestion, urgent

Thank u

Answer Source

You can use a WebClient request to something like ipinfodb, if you register (free) for an api key:

var client = new System.Net.WebClient();
var ip = Request.UserHostAddress;
var url = string.Format("{0}&ip={1}", apiKey, ip);
var info = client.DownloadString(url).ToString();

Then parse and display the info in your page.

There are many IP locator APIs, whichever one you use, the general idea is the same, but you will parse the info result differently depending on the service.

But walther is correct, getting location info from IP addresses isn't always reliable.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download