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的细致内容,更多请关注ki4网别的相干文章!