Client IP Address

Charles Matvchuk asked on April 22, 2015 04:04

Before 8.x I used this piece of code to grab the IP Address of the Current User. Now I do not seem to find it in the changed namespace. Any Ideas where it went to or what I can use now ? CMS.Helpers.HTTPHelper doesn't contain the method.

string clientIp = CMS.GlobalHelper.HTTPHelper.GetUserHostAddress();

Correct Answer

Martin Danko answered on April 22, 2015 12:01

Hi Charles,

Are you aware of special page where you can also check the API changes between Kentico 7 and Kentico 8?

This method is documented there: Kentico API Changes

And also a little bit old but still helpful Macro Reference for Kentico 5.5 can sometimes reveal some magic macro like this simple one:

{%IP%}

Regards, Martin

1 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on April 22, 2015 04:19

Check this out Charles. I know it may not be what you're looking for but it does seem to work.

string ipAddr = RequestContext.UserHostAddress;
3 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on April 22, 2015 04:26

Yes Brandon, it is. I was using the API Changes Tool and had it on 8.1 to 8.2 which doesn't show the method. I needed to set it to 7.0 to 8.0.

2 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on April 22, 2015 04:56 (last edited on April 22, 2015 04:56)

Brandon, is there a Macro to Resolve/Get Current User IP ?

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on April 22, 2015 06:58

Think you'd have to expose that method via a custom macro. Probably the quickest and easiest way.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on April 22, 2015 14:32

WOW Had no idea it was that simple Martin! Thanks!

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on April 22, 2015 18:43

Great Tip. I would be great if the Macro Reference sheets were updated or a complete list of all system macro's was available.

1 votesVote for this answer Mark as a Correct answer

Martin Danko answered on April 22, 2015 19:10

Charles,

I completely agree with you.. it's definitely worth of updating and you as our customer have the power to make it real by sharing your opinion with our Product manager via Kentico UserVoice portal.

So definitely go for it, it's the best way how to say that updated Macro Reference does make sense for you - customers.

Regards, Martin

0 votesVote for this answer Mark as a Correct answer

Chetan Sharma answered on August 11, 2016 11:10

Hi Martin,

No it's an old thread, however when I used {%ip%} in an online form, it returned me IP address of my server. Which I think is correct as pages are processed on the server side.

Now coming back to original question, what is the way to get client's ip address?

Thanks, Chetan

0 votesVote for this answer Mark as a Correct answer

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