Request.UserHostAddress issue with return result “

2019-01-14 10:07发布

问题:

I am trying to get client ip address using

    HttpContext.Request.UserHostAddress;

but it returns ::1.

How to solve this?

回答1:

::1 is for localhost, Maybe this might be useful.



回答2:

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.



回答3:

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!



回答4:

it is not bug actually you are running your application on local host it is just giving you the ip of of local host and it is ipv6 format