gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 16:46:24 24 4
gpt4 key购买 nike

我之前使用下面的代码通过 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

编辑

发现类似问题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.

我还找到了 ISAPI Filter 模块,但无法使其工作:devcentral.f5.com/x_forwarded_for_log_filter_for_windows_servers

最佳答案

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

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

http://kb.parallels.com/6735

建议另一个解决方案here是:

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"

关于asp.net - 无法获取用户 IP 地址(代理/防火墙/负载均衡器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6014816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com