0

So I'm trying to make a system in which I get the user's IP and if he clicked something once then he won't be able to reclick. I'm having hard time trying to figure out how to get the user's IP, and I need your help. Can anybody please send me a code in which I can simply put someone's IP into a string in ASP.NET?

Thanks in advance!

Dan Brooks
  • 89
  • 1
  • 9

2 Answers2

2

Request.UserHostAddress should do it.

Granted that carries a couple caveats, particularly in that it might not work if you're behind a proxy (reverse or otherwise). So be careful with using it. For instance, if someone from Microsoft clicked on your link, someone else from there might not be able to if they were going through the same router.

As a general rule, I'd say this is great if you're working with a limited subset of people (like if it's an intranet site), but you might want to find an alternative if you're going to be targeting everyone. You could look into using cookies, although that's really up to the user not clearing their cookies. The safest way would be through authentication, although I recognize that that can be a hassle for users if you don't already require them to do that.

Matthew Haugen
  • 12,916
  • 5
  • 38
  • 54
0

You can use HttpContext.Current.Request.UserHostAddress but that won't do much good if client is using proxy servers or through NAT (private IP's).

Rahul
  • 76,197
  • 13
  • 71
  • 125