Client IP Address in Load Balanced Scenario

Brenden Kehren asked on January 12, 2015 21:42

Does anyone know if this article is still pertinent in v8.x? I've been able to implement it in v7 without issue but it doesn't seem to be working in v8.x at all.

Correct Answer

Brenden Kehren answered on March 6, 2015 14:08

Thanks for following up Radek. After finally having a bit of time to debug further I found a simple change was needed in the last few lines to assign the actual address.

Old code:

if (!String.IsNullOrWhiteSpace(sClientAddress))
{
    RequestStockHelper.Add("UserHostAddress", sClientAddress);
}

New code:

if (!String.IsNullOrWhiteSpace(sClientAddress))
{
    RequestContext.UserHostAddress = sClientAddress;
}
1 votesVote for this answer Unmark Correct answer

Recent Answers


Radek Macalik answered on March 6, 2015 12:38 (last edited on March 6, 2015 12:38)

Hello.

The article is written and tested for version 7 only. We did not test it for any newer version. Anyways, the problem might be related to differences in API and project structure between Kentico 7 and Kentico 8. Could you please send us an e-mail to support@kentico.com and refer to this forum thread? Thank you.

Best regards, Radek Macalik

0 votesVote for this answer Mark as a Correct answer

Pedro Costa answered on July 9, 2015 12:27

Hi,

We had to change one more line of code for 8.2 in the latest hotfix, instead of :

CMSRequestEvents.Begin.Before += new EventHandler<EventArgs>(SetClientAddress);

use:

RequestEvents.Begin.Execute += new EventHandler<EventArgs>(SetClientAddress);

Not validated by Kentico, but I think that's the correct new method to handle this event.

Cheers, P.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.