为什么我写的方法返回值不对啊,返回本机ip
public static string GetClientIP()
{
string result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
if (null == result || result == String.Empty)
{
result = HttpContext.Current.Request.UserHostAddress;
}
return result;
}
方法是这个!在别的机器上显示正常,可在我电脑上就布可以,谁知道是我电脑哪里出问题了么?我命令提示本里pin出来的ip是正常的呢!问题出哪里了?
string
null
ip
------解决方案-------------------- public static string GetClientIP()
{
IPAddress myIPAddress = (IPAddress)Dns.GetHostAddresses(Dns.GetHostName()).GetValue(1);
return myIPAddress.ToString();
}
用我写的,,,加群217280480