Search code examples
asp.net-mvcload-balancingf5

How to find client IP address in load balanced IIS servers


We have Asp.net MVC application hosted in 2 windows 2012 servers(IIS). These servers are load balanced using F5 and sticky sessions.

We want to find client ip address sending the request through F5. So, we have tried to log Request.UserHostAddress. But, it is logging load balanced interface ip address. Can someone suggests how to find actual client IP address from MVC application?


Solution

  • You will need to configure the BIG-IP to insert an X-Forwarded-For (or similar) header, which you can do in the http profile on newer version via a checkbox, or you can use an iRule to do so in older versions. I'm not sure if your version of IIS natively reads this header or if you need a module to read it, but we have a module for IIS 7+ available on DevCentral.

    I cover the X-Forwarded-For here 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.