Maintaining correct user host IP address in a load balanced environment
This article will show how to ensure the correct IP address will be used in relevant modules (such as Web Analytics, Online marketing or in event logging), when the load balanced environment (or e.g. an SSL offloader) passes the original host IP address in special HTTP header and the CMS uses the address of the balancer instead.
To ensure the correct IP address is used as user host address (and not the one of the balancer server), you will need to customize how we obtain that address. One of the ways is to add processing of the special header, typically x-forwarded-for header, into the App_Code\Application\CMSAppBase.cs.
The best place is to do this is as early as possible, so that all modules will get the same corrected address. The BeforeBeginRequest phase is the most suitable.
First, you will need to detect and get the real client IP address from the HTTP header. You can use HttpContext.Current.Request.Headers collection to get the header.
Then you can set the HTTPHelper.UserHostAddress property, so that it contains the desired real host IP address.
You can set it using:
HTTPHelper.UserHostAddress = address;
FYI, this internally calls
The "address" here is meant to be the detected correct IP address (a string value).
Kentico CMS 7.x