如何在负载平衡的 IIS 服务器中查找客户端 IP 地址

How to find client IP address in load balanced IIS servers

我们有 Asp.net MVC 应用程序托管在 2 windows 2012 服务器 (IIS) 中。这些服务器使用 F5 和粘性会话进行负载平衡。

我们想通过F5查找发送请求的客户端ip地址。因此,我们尝试记录 Request.UserHostAddress。但是,它正在记录负载平衡接口 ip 地址。有人可以建议如何从 MVC 应用程序中找到实际的客户端 IP 地址吗?

您需要配置 BIG-IP 以插入 X-Forwarded-For(或类似的)header,您可以通过复选框在较新版本的 http 配置文件中执行此操作,或者您可以使用 iRule 在旧版本中执行此操作。我不确定您的 IIS 版本是否可以本地读取此 header 或者您是否需要一个模块来读取它,但我们在 DevCentral 上提供了一个 module for IIS 7+

我覆盖了X-Forwarded-Forhere in an article checkbox in the http profile in this article, and if you are on an earlier version and need the iRule, you can go simple and basic or complex.