HttpContext.Current.Request.UserHostAddress is null

ぐ巨炮叔叔 提交于 2019-12-10 02:15:51

问题


  1. In my Dev Machine HttpContext.Current.Request.UserHostAddress is null. Why? how can I turn it on?
  2. How can I get list of Ips in case of a proxy client?

WCF Service with ASP.net 4 window7.

Thanks


回答1:


to avoid this problem you can parse the HTTP_X_FORWARDED_FOR for the last entery 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"];
}

Hope this will helps you



来源:https://stackoverflow.com/questions/7674731/httpcontext-current-request-userhostaddress-is-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!