0

I have an ASP.NET MVC web app and I need to get the client IP address.

I researched this and there are two main possibilities:

  1. to retrieve the IP using HTTP headers
  2. to retrieve it using HttpContext.Request.UserHostAddress

The problem with the first method is that the IP can easily be spoofed.

The problem with the second method is that if the client is behind a proxy, it retrieves the client proxy - not the client's own IP.

(See here - this is the best resource I found in SO describing the above problem)

My question: how can I retrieve the client's IP address in a way that cannot be spoofed and to get his own IP address, not his proxy's IP - is it possible?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ben.S
  • 708
  • 1
  • 5
  • 24

0 Answers0