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 取出的是被分配的保留地址
注:X-Forwarded-For:简称XFF头,它代表代表客户端,也就是HTTP的请求端真实的IP,只有在通过了HTTP 代理或者负载均衡服务器时才会添加该项
以上就是ASP.NET 获取 客户端IP的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1
| 本站CDN由 数掘科技 提供