无法获取用户 IP 地址(代理/防火墙/负载均衡器)
我之前使用下面的代码通过asp.net获取客户端IP,但在我转移到VDS之后,这个函数开始只返回我的子网掩码,即178.18.198.1或178.18.198.2。 谁能帮我解决这个问题吗?
Private Function GetIPAddress() As String
Dim sIPAddress As String = Nothing
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If String.IsNullOrEmpty(sIPAddress) Then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
Return sIPAddress
End Function
编辑
此处发现类似问题:
已经部署了很多2008 32位 使用 Citrix 的标准 Web 服务器 netscaler isapi(netscaler 是 负载均衡器),在所有情况下 客户端IP地址记录在 标准 IIS 日志。在一个新项目上我 被要求部署2008 R2, 配置 IIS 7.5 与 我过去如何配置 IIS 7.0, 然而这次客户端IP是 返回负载均衡器地址 日志。这是奇怪的部分,我 安装了“高级日志记录”,它是 显示客户端IP地址 正确地,所以 isapi 正在做它的 工作。已经用谷歌搜索死这个了 并需要一些建议。
我还找到了 ISAPI 过滤器模块,但无法使其工作: devcentral.f5.com/ x_forwarded_for_log_filter_for_windows_servers
I used code below to get client ip with asp.net before but after I moved to VDS this function begin returning only my subnet mask which is 178.18.198.1 or 178.18.198.2.
Can anyone help me with this problem?
Private Function GetIPAddress() As String
Dim sIPAddress As String = Nothing
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If String.IsNullOrEmpty(sIPAddress) Then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
Return sIPAddress
End Function
EDIT
Found similar problem here:
Have deployed many 2008 32 bit
standard web servers using the citrix
netscaler isapi (the netscaler being a
load balancer), in all cases the
client IP address is logged in the
standard IIS logs. On a new project I
was asked to deploy 2008 R2,
configured IIS 7.5 identically with
how I configured IIS 7.0 in the past,
this time however the client ip is
returning the load balancer address in
the logs. Here is the weird part, I
installed "advanced logging" and it is
showing the client IP address
properly, so the isapi is doing its
job. Have googled this one to death
and could use some advice.
I also found ISAPI Filter module but cannot make it work: devcentral.f5.com/x_forwarded_for_log_filter_for_windows_servers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过在源代码文件中使用 HTTP_CLIENT_IP 而不是 REMOTE_ADDR 解决了问题。
有关 IIS 日志的问题已通过按照此处的建议安装 IIS 高级日志记录模块来解决。另外,在安装高级日志记录后,我收到错误“503:服务不可用”,但通过向“每个人”授予 Program Files\IIS 文件夹的读写权限并启动失败的应用程序池解决了此问题。
http://kb.parallels.com/6735
建议的另一个解决方案这里是:
Problem solved by using HTTP_CLIENT_IP instead of REMOTE_ADDR in sourcecode files.
The problem about IIS Logs was solved by installing IIS Advanced Logging module as suggested here. Also I got error "503: Service Unavailable" after installing Advanced Logging but solved this by granting read-write permissions to Everyone for Program Files\IIS folder and started failed application pools.
http://kb.parallels.com/6735
Another solution suggested here is:
我
在 C# 中使用。这对你有用吗?
I use
In C#. Does that work for you?