使用ASP.NET,显示一个类似的国家,州和城市的主网页的访问者位置 [英] using ASP.NET to display the visitor location like country, state and city in master page

查看:175
本文介绍了使用ASP.NET,显示一个类似的国家,州和城市的主网页的访问者位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ASP.NET来得到这样的国家,州和城市的访问者位置,我看到一些例子都是基于IP地址来获取详细信息(基于一些免费服务),现在我的问题是上面的例子,只有服务注册工作的I​​P地址,但现在我的任务是当用户浏览我的asp.net网站,显示国家,州和城市如何可能的话,请给我任何建议,紧急

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 asp.net website, display the Country, state and city how it possible, please give me any suggestion, urgent

感谢ü
hemanth

Thank u hemanth

推荐答案

您可以使用Web客户端请求像ipinfodb,如果你的注册(免费),API密钥:

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("http://api.ipinfodb.com/v3/ip-city/?key={0}&ip={1}", apiKey, ip);
var info = client.DownloadString(url).ToString();

然后解析,并显示在页面的信息

有很多IP定位的API,哪一个你使用的总体思路是一样的,但你会解析的结果不同,具体取决于该服务的信息。

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.

但瓦尔特是否正确,从IP地址的位置信息并不总是可靠的。

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

这篇关于使用ASP.NET,显示一个类似的国家,州和城市的主网页的访问者位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆