Request.UserHostAddress 出现返回结果“::1”的问题
我正在尝试使用获取客户端 IP 地址
HttpContext.Request.UserHostAddress;
,但它返回 ::1
。
怎么解决这个问题呢?
I am trying to get client ip address using
HttpContext.Request.UserHostAddress;
but it returns ::1
.
How to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
::1
用于localhost
,也许这个可能有用。
::1
is forlocalhost
, Maybe thismight be useful.
这不是一个错误 - 您正在从 localhost 连接到 启用 IPv6 的计算机。
::1
是环回地址 - 双冒号表示“省略零”,因此该地址对应于地址 1。如果您正在开发新软件,我强烈建议您不要禁用 IPv6。实施支持最简单的时间就是从一开始,花时间寻找解决方法可能只是浪费精力,推迟不可避免的事情。
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.
虽然这确实不是一个错误,但也许您可以检查 此链接,您的问题得到了很好的描述和“解决”。它表示问题的行为方式取决于操作系统,因为用户通过注释
::1
行修复了在 Windows Server 2008 中运行的应用程序中的一些问题hosts 文件,而他必须在 Windows 7 中取消注释。希望你能解决这个问题!祝你好运!
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!
这不是错误,实际上您正在本地主机上运行应用程序,它只是为您提供本地主机的 IP,并且它是 ipv6 格式
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