有这样的情况:我有服务器my.qwe (192.168.0.1),它的地址是均衡器192.168.0.2,它在192.168.0.3或192.168.0.4上抛出客户端。我从机器192.168.0.5发出请求。问:如何获取我机器的ip地址。注意:我使用了
HttpContext.Current.Request.ServerVariables["HTTP_X_COMING_FROM"]
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED"]
HttpContext.Current.Request.ServerVariables["HTTP_VIA"]
HttpContext.Current.Request.ServerVariables["HTTP_COMING_FROM"]
HttpContext.Current.Request.ServerVariables["HTTP_FORWARDED_FOR"]
HttpContext.Current.Request.ServerVariables["HTTP_FORWARDED"]
HttpContext.Current.Request.ServerVariables["HTTP_FROM"]
HttpContext.Current.Request.ServerVariables["HTTP_PROXY_CONNECTION"]
HttpContext.Current.Request.ServerVariables["CLIENT_IP"]
HttpContext.Current.Request.ServerVariables["REMOTE_HOST"]
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]
HttpContext.Current.Request.ServerVariables["FORWARDED"]
给出均衡器192.168.0.2的空字符串或ip地址,我该怎么办?
发布于 2018-08-30 09:25:02
您可以使用以下任一选项:
Request.UserHostAddress
或者:
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]
这两种方法都应该有效。你可以在这里找到更多关于它的信息:
https://stackoverflow.com/questions/52090196
复制相似问题