Which version are you using? v6, v7, v8?
You have to ensure your load balancer is passing one of the parameters below through:
client-ip, x-forwarded-for, http_client_ip, http_x_forwarded_for
If it isn't passing one of those, none of the below will work.
For v6/7 I use this:
private void SetClientAddress(object sender, EventArgs e)
{
string sClientAddress = null;
NameValueCollection oColl = null;
if ((HttpContext.Current != null) && (HttpContext.Current.Request != null))
{
oColl = HttpContext.Current.Request.Headers;
foreach (string sKey in new string[] { "CLIENT-IP", "X-FORWARDED-FOR" })
{
sClientAddress = oColl[sKey];
if ((sClientAddress != null) && (sClientAddress == "::1"))
{
sClientAddress = null;
}
else if (!String.IsNullOrWhiteSpace(sClientAddress))
{
break;
}
}
if (String.IsNullOrWhiteSpace(sClientAddress))
{
oColl = HttpContext.Current.Request.ServerVariables;
foreach (string sKey in new string[] { "HTTP_CLIENT_IP", "HTTP_X_FORWARDED_FOR" })
{
sClientAddress = oColl[sKey];
if ((sClientAddress != null) && (sClientAddress == "::1"))
{
sClientAddress = null;
}
else if (!String.IsNullOrWhiteSpace(sClientAddress))
{
break;
}
}
}
}
if (!String.IsNullOrWhiteSpace(sClientAddress))
{
RequestStockHelper.Add("UserHostAddress", sClientAddress);
}
}
In v8, you have to change
RequestStockHelper.Add("UserHoseAddress", sClientAddress);
To:
RequestContext.UserHostAddress = sClientAddress;