By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,166 Members | 1,130 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,166 IT Pros & Developers. It's quick & easy.

Request.UserHostAddress, Vista & IIS7

P: n/a
Hi,

Now that the VS.NET 2005 SP1 update patch is with us, I'm in the process of
moving my main development environment onto 64-bit Vista Business Edition -
so far, so good...

However, there is a bit of a gotcha with Request.UserHostAddress...

Under IIS6 and earlier, that would return a standard xxx.xxx.xxx.xxx IP
address. However, Vista enables IP6 by default, which makes
Request.UserHostAddress return an IP6 address e.g.
"fe80::2032:39ab:3f57:fffb%10"

Easy enough to disable IP6, of course, but does anyone know a way to return
an IP4 address from IIS7 without disabling IP6, or mucking about with
LMHOSTS...

Haven't been able to find a way so far...
http://west-wind.com/WebLog/posts/8839.aspx
http://forums.asp.net/thread/1667538.aspx

Any assistance gratefully received.

Mark

Apr 26 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
This article shows you how to set Vista to prefer IPv4 to IPv6 when attempting connections:

http://www.microsoft.com/technet/com...uy/cg1005.mspx

To selectively disable Pv6 components and configure behaviors for IPv6 in Windows Vista,
create and configure the following registry value (DWORD type):

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Servic es\tcpip6\Parameters\DisabledComponents

DisabledComponents is set to 0 by default.

The DisabledComponents registry value is a bit mask that controls the following series of flags,
starting with the low order bit (Bit 0):

Bit 0 Set to 1 to disable all IPv6 tunnel interfaces, including ISATAP, 6to4, and Teredo tunnels.
Default value is 0.

Bit 1 Set to 1 to disable all 6to4-based interfaces. Default value is 0.

Bit 2 Set to 1 to disable all ISATAP-based interfaces. Default value is 0.

Bit 3 Set to 1 to disable all Teredo-based interfaces. Default value is 0.

Bit 4 Set to 1 to disable IPv6 over all non-tunnel interfaces, including LAN interfaces and
Point-to-Point Protocol (PPP)-based interfaces. Default value is 0.

Bit 5 Set to 1 to modify the default prefix policy table to prefer IPv4 to IPv6 when
attempting connections. Default value is 0.

So, you'd set the first 4 bits to 0 and bit 5 to 1.

That will allow IPv6, but the system will prefer IPv4.

To only prefer IPv4 over IPv6 (what you want), set the value to 0x20
To disable IPv6 over all interfaces *and* prefer IPv4 to IPv6, set it to 0xFF

You must restart the computer for the changes to the DisabledComponents registry value to take
effect.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:uj**************@TK2MSFTNGP05.phx.gbl...
Hi,

Now that the VS.NET 2005 SP1 update patch is with us, I'm in the process of moving my main
development environment onto 64-bit Vista Business Edition - so far, so good...

However, there is a bit of a gotcha with Request.UserHostAddress...

Under IIS6 and earlier, that would return a standard xxx.xxx.xxx.xxx IP address. However, Vista
enables IP6 by default, which makes Request.UserHostAddress return an IP6 address e.g.
"fe80::2032:39ab:3f57:fffb%10"

Easy enough to disable IP6, of course, but does anyone know a way to return an IP4 address from
IIS7 without disabling IP6, or mucking about with LMHOSTS...

Haven't been able to find a way so far...
http://west-wind.com/WebLog/posts/8839.aspx
http://forums.asp.net/thread/1667538.aspx

Any assistance gratefully received.

Mark

Apr 26 '07 #2

P: n/a
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:u4**************@TK2MSFTNGP05.phx.gbl...
This article shows you how to set Vista to prefer IPv4 to IPv6 when
attempting connections:
Superb! Muchas gracias, hombron...

Apr 26 '07 #3

P: n/a
re:
Muchas gracias, hombron...
<chuckle>

You're quite welcome, Mark.
It just so happened that I'd just looked up the very same issue for a client.

:-)


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:O2****************@TK2MSFTNGP04.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:u4**************@TK2MSFTNGP05.phx.gbl...
>This article shows you how to set Vista to prefer IPv4 to IPv6 when attempting connections:

Superb! Muchas gracias, hombron...

Apr 27 '07 #4

P: n/a
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:ez**************@TK2MSFTNGP05.phx.gbl...
It just so happened that I'd just looked up the very same issue for a
client.
Aw - now you've gone and shattered my illusion...

Apr 27 '07 #5

P: n/a
The timing was perfect... :-)


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:eC**************@TK2MSFTNGP04.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:ez**************@TK2MSFTNGP05.phx.gbl...
>It just so happened that I'd just looked up the very same issue for a client.
Aw - now you've gone and shattered my illusion...

Apr 27 '07 #6

P: n/a
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:u4**************@TK2MSFTNGP05.phx.gbl...
This article shows you how to set Vista to prefer IPv4 to IPv6 when
attempting connections:

http://www.microsoft.com/technet/com...uy/cg1005.mspx
I think I've found a way to return the IP4 address even when IP6 is on...

Dns.GetHostAddresses(Dns.GetHostName()) returns an array if IP addresses for
the current host and, so far, the IP4 address always seems to be the fourth
element of the array i.e.

[0]: {fe80::288f:1d8f:3f57:fffb%10}
[1]: {fe80::7133:8615:3971:49d1%8}
[2]: {fe80::5efe:192.168.0.4%13}
[3]: {192.168.0.4}
[4]: {2001:0:4136:e38e:288f:1d8f:3f57:fffb}

Therefore:

using System.Net;
string strIP4Address =
Dns.GetHostAddresses(Dns.GetHostName())[3].ToString();

I need to do a bit more testing to see what that returns on XP / Win2k3s.

Also, it's almost certainly an extremely bad idea to rely on the numerical
position of the element within the array...

--
http://www.markrae.net

Apr 29 '07 #7

P: n/a
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:uY**************@TK2MSFTNGP05.phx.gbl...
I need to do a bit more testing to see what that returns on XP / Win2k3s.
And here we go:

using System.Net;

public string GetIP4Address()
{
string strIP4Address = String.Empty;

foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (objIP.AddressFamily.ToString() == "InterNetwork")
{
strIP4Address = objIP.ToString();
break;
}
}
return strIP4Address;
}

See here for further details:
http://msdn2.microsoft.com/en-us/lib...essfamily.aspx

Apr 29 '07 #8

P: n/a
Good job, Mark!

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:%2****************@TK2MSFTNGP02.phx.gbl...
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:uY**************@TK2MSFTNGP05.phx.gbl...
>I need to do a bit more testing to see what that returns on XP / Win2k3s.

And here we go:

using System.Net;

public string GetIP4Address()
{
string strIP4Address = String.Empty;

foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (objIP.AddressFamily.ToString() == "InterNetwork")
{
strIP4Address = objIP.ToString();
break;
}
}
return strIP4Address;
}
See here for further details:
http://msdn2.microsoft.com/en-us/lib...essfamily.aspx

Apr 29 '07 #9

P: n/a
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:eI**************@TK2MSFTNGP05.phx.gbl...
Good job, Mark!
Thanks.

Apr 29 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.