存在这种情况:我有服务器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地址,我该怎么办?
答案 0 :(得分:-1)
您可以使用:
Request.UserHostAddress
或者:
HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]
两者都应该起作用。您可以在此处找到有关此信息的更多信息: