Page.Request.UserHostAddress is in an invalid form

2019-04-06 15:37发布

Sometimes my ASP.NET application returns a value of "::1" when querying Page.Request.UserHostAddress.

I can't see any pattern as to when it returns a correct IP address vs when it returns the incorrectly formatted string. It will work for half a day and then stop working for an hour randomly. Any thoughts?

Edit:

Okay, it's the loopback address for IPv6. :) Which leads to the further question... When/why would IPv6 be used on some occasions and not others?

5条回答
男人必须洒脱
2楼-- · 2019-04-06 15:51

::1 is the IPv6 loopback address. Equivalent to 127.0.0.1 for IPv4.

查看更多
神经病院院长
3楼-- · 2019-04-06 15:51

I guess you are on the server, browse your website and page from a remote machine you should see the client IPv4 address.

查看更多
We Are One
4楼-- · 2019-04-06 15:53

I believe you can override this by commenting out the IPv6 localhost entry your hosts file. The file is at:

C:\Windows\System32\drivers\etc\hosts

You'll want to modify the last couple of lines to look like this:

127.0.0.1 localhost

# ::1 localhost

查看更多
Fickle 薄情
5楼-- · 2019-04-06 16:14

I believe the Visual Studio Web Server defaults to IPv6, could can turn off the support in the browsers, here is a post about a bug that causes performance issues with Firefox and IPv6.

查看更多
霸刀☆藐视天下
6楼-- · 2019-04-06 16:15

That's also a correct IP address, but it's an IPv6 address instead of an IPv4 address.

查看更多
登录 后发表回答