当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET 获取客户端IP方法

ASP.NET 获取客户端IP方法

2017年12月08日  | 移动技术网IT编程  | 我要评论

淮安个人二手房网,灰太狼图片,疤脸人

话不多说,请看代码:

string requestclientipaddress = httpcontext.current.request.servervariables["http_x_forwarded_for"];
if (string.isnullorempty(requestclientipaddress))
 requestclientipaddress = httpcontext.current.request.servervariables["remote_addr"];
if (string.isnullorempty(requestclientipaddress))
 requestclientipaddress = httpcontext.current.request.userhostaddress;

经过测试  存在负载均衡的时候 ,httpcontext.current.request.servervariables["http_x_forwarded_for"] 取出的是真实的客户端 ip地址 ,而httpcontext.current.request.servervariables["remote_addr"] 和 httpcontext.current.request.userhostaddress 取出的是被分配的保留地址

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持移动技术网!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网