Request.UserHostAddress issue with return result “

2019-01-14 10:11发布

I am trying to get client ip address using

    HttpContext.Request.UserHostAddress;

but it returns ::1.

How to solve this?

4条回答
干净又极端
2楼-- · 2019-01-14 10:47

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楼-- · 2019-01-14 10:54

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

查看更多
贪生不怕死
4楼-- · 2019-01-14 11:03

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!

查看更多
女痞
5楼-- · 2019-01-14 11:04

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

查看更多
登录 后发表回答