无法获取用户 IP 地址(代理/防火墙/负载均衡器)

发布于 2024-11-07 18:57:13 字数 1074 浏览 5 评论 0原文

我之前使用下面的代码通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

请别遗忘我 2024-11-14 18:57:13

通过在源代码文件中使用 HTTP_CLIENT_IP 而不是 REMOTE_ADDR 解决了问题。

有关 IIS 日志的问题已通过按照此处的建议安装 IIS 高级日志记录模块来解决。另外,在安装高级日志记录后,我收到错误“503:服务不可用”,但通过向“每个人”授予 Program Files\IIS 文件夹的读写权限并启动失败的应用程序池解决了此问题。

http://kb.parallels.com/6735

建议的另一个解决方案这里是:

在 NetScaler 上的“加载
平衡”,“服务”然后在
高级选项卡,在设置下,检查
“使用源 IP”框和
然后在标头字段中输入“客户端 IP”
“客户端IP”

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:

On the NetScaler under "load
balancing", "Services" then under the
advanced tab, under settings, check
the box for "Use Source IP" and
"Client IP" then in the Header field
"CLIENT-IP"

调妓 2024-11-14 18:57:13

IP.Text = Request.UserHostAddress;

在 C# 中使用。这对你有用吗?

I use

IP.Text = Request.UserHostAddress;

In C#. Does that work for you?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文