string ip = "";
string HostName = string.Empty;
string ipv4 = String.Empty;
if (string.IsNullOrEmpty(System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]))
ip = Convert.ToString(System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
if (string.IsNullOrEmpty(ip))
ip = System.Web.HttpContext.Current.Request.UserHostAddress;
foreach (IPAddress ipAddr in Dns.GetHostEntry(ip).AddressList)
{
if (ipAddr.AddressFamily.ToString() == "InterNetwork")
{
ipv4 = ipAddr.ToString();
}
}
HostName= Dns.GetHostEntry(ip).HostName;
上面代码在本地测试成功,但是发布后,只能获取到计算机名,ip地址是空的
不知道为什么