I am trying to get client ip address using
HttpContext.Request.UserHostAddress;
but it returns ::1
.
How to solve this?
::1
is for localhost
, Maybe this
might be useful.
This is not a bug - you're connecting from localhost on an IPv6 enabled machine. ::1
is the loopback address - a double colon means "omitted zeroes", so this address corresponds to address 1.
If you're developing new software, I'd urge you not to disable IPv6. The easiest time to implement support is right from the start, and spending time on workarounds is perhaps just wasting effort putting off the inevitable.
Although it's true that this is not a bug, maybe you can check this link, where your problem is nicely described and "solved". It says that the way the issue behaves depends on the operating system, since a user fixed some problems in an application running in Windows Server 2008 by commenting the ::1
line in the hosts file, while he had to uncomment it in Windows 7.
Hope you managed to solve that! Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With