Request.Url.Host 获取请求服务器的地址
放在局域网测试都没有问题,
可是放到公网,ip地址更换为郁闷,就不能正常获取地址,经常获取到的是内网的ip
求解释,求大神帮忙
------解决方案--------------------------------------------------------
想获得外网地址,参考http://zhidao.baidu.com/question/142477137
------解决方案--------------------------------------------------------
public static string GetIP()
{
string result = String.Empty;
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;
}
if (null == result
------解决方案--------------------------------------------------------
result == String.Empty)
{
return "0.0.0.0";
}
return result;
}
------解决方案--------------------------------------------------------
试试这个
Request.Url.Authority
------解决方案--------------------------------------------------------
直接在配置文件配也可以的楼主!不一定要用代码获取