How do I make my local windows 7 environment use ipv4?
I have an ASPX MVC v3 applications that is using
String sourceIp = Request.ServerVariables["REMOTE_ADDR"];
to get the IP Address. The problem is that this is returning me the IPv6 version. I need the IPv4 version.
My understanding is that there is nothing the website can do to get the IPv4 version, what I need to do is tell the server (my computer, this is local development) to use IPv4 instead of IPv6.
We have turned off IPv6 in the Local Area Connection Status -> Properties
but its still grabbing the IPv6 version.
How can I get the IPv4 address?
Note: I need the IPv4 because we are using a third party service that requires the ip as one of the parameters in IPv4 format.
ANSWER
开发者_运维百科Need to wait 8 hours before I can post answer
Worked out an easy work around. When I press debug it opens up IE with http://localhost:8023/mysite
, if change the localhost
to 127.0.0.1
then it will use 127.0.0.1 as the ip address, which is IPv4 format.
I recommend checking the HTTP_X_FORWARDED_FOR value first as discussed in Phil Haack's post "A Gotcha Identifying the User's IP Address"
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
Here is a great code sample showing exactly how to do it
Worked out an easy work around. When I press debug it opens up IE with http://localhost:8023/mysite, if change the localhost to 127.0.0.1 then it will use 127.0.0.1 as the ip address, which is IPv4 format.
精彩评论