HttpContext.Current.Request.UserHostAddress为null [英] HttpContext.Current.Request.UserHostAddress is null
本文介绍了HttpContext.Current.Request.UserHostAddress为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
- 在我的开发机
HttpContext.Current.Request.UserHostAddress
为空。
为什么呢?我怎么能打开它? - 如何在代理客户的情况下获得的IPS列表?
- In my Dev Machine
HttpContext.Current.Request.UserHostAddress
is null. Why? how can I turn it on? - How can I get list of Ips in case of a proxy client?
WCF服务与ASP.net 4 WINDOW7。
WCF Service with ASP.net 4 window7.
感谢
推荐答案
要避免这个问题,你可以解析最后entery IP的HTTP_X_FORWARDED_FOR。
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
这篇关于HttpContext.Current.Request.UserHostAddress为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文