HttpContext.Current.Request.UserHostAddress 为空

2024-04-30

  1. 在我的开发机器中HttpContext.Current.Request.UserHostAddress一片空白。 为什么?我怎样才能打开它?
  2. 如果是代理客户端,如何获取 Ips 列表?

WCF 服务与 ASP.net 4 windows 7。

Thanks


为了避免这个问题,您可以解析 HTTP_X_FORWARDED_FOR 来获取最后输入的 IP。

ip=Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ;
if (!string.IsNullOrEmpty(ip))
{
   string[] ipRange = ip.Split(',');
   int le = ipRange.Length - 1;
   string trueIP = ipRange[le];
}
else
{
   ip=Request.ServerVariables["REMOTE_ADDR"];
}

希望这会对您有所帮助

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

HttpContext.Current.Request.UserHostAddress 为空 的相关文章

随机推荐