0

I'm trying to reach user's IP address. When I try several methods but it always returns "::1"

My Code Sample : string ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

Cœur
  • 37,241
  • 25
  • 195
  • 267
Erdem Köşk
  • 190
  • 1
  • 10
  • Well `::1` is the same as `127.0.0.1` which is your loopback address. Are you running this on your machine in debug or something? – Equalsk Mar 20 '17 at 16:25
  • I'm debug now. But I want to find users location with using ip adress. How ca nacess user ip ? – Erdem Köşk Mar 20 '17 at 16:28
  • 3
    Your code is fine and should work in production, you're getting the `::1` address because you're in debug. See the answer from `mangokun` here http://stackoverflow.com/questions/735350/how-to-get-a-users-client-ip-address-in-asp-net – Equalsk Mar 20 '17 at 16:28
  • 1
    Note that any code you write may not work if your application is behind a reverse proxy - you are likely to only get the IP of the proxy server instead. You may have some luck checking the `X-Forwarded-For` HTTP header if that is the case. I'm also not sure what IP you will get for a .Net Core Kestrel app with IIS as a proxy. – DavidG Mar 20 '17 at 16:41

0 Answers0