Asp.net 客户端国家/地区名称显示空
我使用了以下代码来获取客户端的国家/地区名称。为此我用了 dll库。但是当运行我的代码时,这个国家没有 显示任何价值。我还使用了公共IP。那么我怎样才能得到我的国家名呢Asp.net 客户端国家/地区名称显示空,asp.net,Asp.net,我使用了以下代码来获取客户端的国家/地区名称。为此我用了 dll库。但是当运行我的代码时,这个国家没有 显示任何价值。我还使用了公共IP。那么我怎样才能得到我的国家名呢 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Net; using WorldDomination.Net; public static string GetLocation()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using WorldDomination.Net;
public static string GetLocation()
{
string userHostIpAddress = new WebClient().DownloadString("http://icanhazip.com");
string country = String.Empty;
string iso3166TwoLetterCode = String.Empty;
IPAddress ipAddress;
if (IPAddress.TryParse(userHostIpAddress, out ipAddress))
{
country = ipAddress.Country(); // return value: UNITED STATES
iso3166TwoLetterCode = ipAddress.Iso3166TwoLetterCode(); // return value: US
}
return country;
}
代码使用来自Webnet77的数据库(根据他们的Codeplex站点)。他们可以用他们的解决方案解决您的ip问题吗?如果是这样,请更新您的数据库,Codeplex站点自2008年以来没有新版本。但是如果我将我的ip 203.76.115.10(发出请求的远程主机(或代理服务器)的ip地址)直接分配给userHostIpAddress,我可以获得正确的位置。是否有任何方法可以检索该字符串并将其设置为userHostIpAddress?然后检查该字符串是否包含额外的数据,可能是换行符。尝试调用WebClient.DownloadString的结果中的.Trim()。我没有获得ipAddress.Country()此Country方法您能帮我吗?