获取ipaddress和访问您网站的每个用户的位置

时间:2020-12-10 01:26:16

How do you get the ipaddress and location of every website vistor of your website through Asp.Net?

你如何通过Asp.Net获得你网站的每个网站的ipaddress和位置?

Thanks

6 个解决方案

#1


4  

To get the user's IP use:

要获得用户的IP使用:

Request.UserHostAddress

You can use this webservice to get their geographic location. http://iplocationtools.com/ip_location_api.php

您可以使用此Web服务获取其地理位置。 http://iplocationtools.com/ip_location_api.php

#2


3  

 string VisitorIPAddress = Request.UserHostAddress.ToString();

and based on the ipaddress you can narrow down the location: find the geographical location of a host

并且基于ipaddress,您可以缩小位置:找到主机的地理位置

#3


1  

Request.UserHostAddress won’t work if you're behind a proxy. Use this code:

如果您在代理后面,Request.UserHostAddress将不起作用。使用此代码:

public static String GetIPAddress()
{
    String ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (string.IsNullOrEmpty(ip))
        ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    else
        ip = ip.Split(',')[0];

    return ip;
}

Note that HTTP_X_FORWARDED_FOR should be used BUT as it can return multiple IP addresses separated by a comma you need to use the Split function. See this page for more info.

请注意,应该使用HTTP_X_FORWARDED_FOR,因为它可以返回由逗号分隔的多个IP地址,您需要使用Split函数。有关详细信息,请参阅此页面。

#4


0  

Well the following property should give you the IP Address of teh client (or the clients proxy server)

以下属性应该为您提供客户端(或客户端代理服务器)的IP地址

Request.UserHostAddress

As for location, you'd need to use some GeoIP/GeoLocation plugin like MaxMind to figure that out.

至于位置,你需要使用一些像MaxMind这样的GeoIP / GeoLocation插件来解决这个问题。

http://www.maxmind.com/

#5


0  

To get the IP do:

获取IP做:

Request.UserHostAddress

And you can map IP to location using a webservice (slower) or a database (faster) like this: http://ip-to-country.webhosting.info/node/view/5

你可以使用webservice(较慢)或数据库(更快)将IP映射到位置:http://ip-to-country.webhosting.info/node/view/5

#6


0  

It's server technology-agnostic, but I'd recommend piggy-backing on Google's AJAX loader: http://code.google.com/apis/ajax/documentation/#ClientLocation

它与服务器技术无关,但我建议在Google的AJAX加载器上备份:http://code.google.com/apis/ajax/documentation/#ClientLocation

It's in Javascript and will even give you the person's city/state/country (well, it takes a guess based on IP address). Post it back to the server and it's available to you in ASP.NET or whatever.

它是在Javascript中,甚至会给你这个人的城市/州/国家(好吧,它根据IP地址进行猜测)。将其发布回服务器,它可以在ASP.NET或其他任何地方使用。

#1


4  

To get the user's IP use:

要获得用户的IP使用:

Request.UserHostAddress

You can use this webservice to get their geographic location. http://iplocationtools.com/ip_location_api.php

您可以使用此Web服务获取其地理位置。 http://iplocationtools.com/ip_location_api.php

#2


3  

 string VisitorIPAddress = Request.UserHostAddress.ToString();

and based on the ipaddress you can narrow down the location: find the geographical location of a host

并且基于ipaddress,您可以缩小位置:找到主机的地理位置

#3


1  

Request.UserHostAddress won’t work if you're behind a proxy. Use this code:

如果您在代理后面,Request.UserHostAddress将不起作用。使用此代码:

public static String GetIPAddress()
{
    String ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if (string.IsNullOrEmpty(ip))
        ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
    else
        ip = ip.Split(',')[0];

    return ip;
}

Note that HTTP_X_FORWARDED_FOR should be used BUT as it can return multiple IP addresses separated by a comma you need to use the Split function. See this page for more info.

请注意,应该使用HTTP_X_FORWARDED_FOR,因为它可以返回由逗号分隔的多个IP地址,您需要使用Split函数。有关详细信息,请参阅此页面。

#4


0  

Well the following property should give you the IP Address of teh client (or the clients proxy server)

以下属性应该为您提供客户端(或客户端代理服务器)的IP地址

Request.UserHostAddress

As for location, you'd need to use some GeoIP/GeoLocation plugin like MaxMind to figure that out.

至于位置,你需要使用一些像MaxMind这样的GeoIP / GeoLocation插件来解决这个问题。

http://www.maxmind.com/

#5


0  

To get the IP do:

获取IP做:

Request.UserHostAddress

And you can map IP to location using a webservice (slower) or a database (faster) like this: http://ip-to-country.webhosting.info/node/view/5

你可以使用webservice(较慢)或数据库(更快)将IP映射到位置:http://ip-to-country.webhosting.info/node/view/5

#6


0  

It's server technology-agnostic, but I'd recommend piggy-backing on Google's AJAX loader: http://code.google.com/apis/ajax/documentation/#ClientLocation

它与服务器技术无关,但我建议在Google的AJAX加载器上备份:http://code.google.com/apis/ajax/documentation/#ClientLocation

It's in Javascript and will even give you the person's city/state/country (well, it takes a guess based on IP address). Post it back to the server and it's available to you in ASP.NET or whatever.

它是在Javascript中,甚至会给你这个人的城市/州/国家(好吧,它根据IP地址进行猜测)。将其发布回服务器,它可以在ASP.NET或其他任何地方使用。