- 在我的开发机器中
HttpContext.Current.Request.UserHostAddress
为空。 为什么?我怎样才能打开它? - 如果是代理客户端,如何获取 Ips 列表?
WCF 服务与 ASP.net 4 window7。
谢谢
最佳答案
为避免此问题,您可以解析最后输入 IP 的 HTTP_X_FORWARDED_FOR。
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"];
}
希望对你有帮助
关于c# - HttpContext.Current.Request.UserHostAddress 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7674731/