简体   繁体   English

ASP.NET中的网站访问者位置

[英]Website visitor location in ASP.NET

My ASP.NET website needs to know the city and country of the visiting user. 我的ASP.NET网站需要知道访问用户的城市和国家。 I have tried following code: 我尝试了以下代码:

string ip = HttpContext.Current.Request.UserHostAddress.ToString();

And then making a web request to http://api.hostip.info/get_html.php?ip=ip 然后向http://api.hostip.info/get_html.php?ip=ip发出Web请求

This method returns me correct user location in some cases, but when user's ISP has hosted server in other country or city, then instead of giving me user's current city (from where he is browsing the website) it gives me the server hosted location. 在某些情况下,此方法可为我返回正确的用户位置,但是当用户的ISP在其他国家或城市托管服务器时,则不给我用户当前所在的城市(他正在浏览网站的位置),而是为我提供服务器的托管位置。

How can I get the user's location regardless of where his ISP has hosted the server? 无论用户的ISP托管服务器在哪里,如何获取用户的位置? Like Google does in Google Maps (where browser asks for permission to share location). 就像Google在Google Maps中所做的那样(浏览器要求共享位置信息)。 Or any other better way? 还是其他更好的方法?

The answer to your problems 您问题的答案

See msdn code sample 请参阅msdn代码示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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