In the properties section of my network card, on windows server 2008, i have IPV6 disabled, leaving only IPV4 enabled.
However in ASP.NET, Request.UserHostAddress returns ::1 , an IPV6 address.
Has anyone got any idea how to revert back to IPV4?
In the properties section of my network card, on windows server 2008, i have IPV6 disabled, leaving only IPV4 enabled.
However in ASP.NET, Request.UserHostAddress returns ::1 , an IPV6 address.
Has anyone got any idea how to revert back to IPV4?
If you re connecting to localhost (::1 / 127.0.0.1), you re not using the network card that your server has, but rather like a virtual card that windows has. I don t think there is anyway to configure the loopback card and removing IPv6 from it, not without removing support from the whole system, but in Win2008 you probably can t do that anymore.
You can verify that your physical card isn t being used by running network packet capturing utils. In windows, you can never sniff out the traffic that walks the virtual loopback card.
That said, should you access from a different machine (through a connection that will be passing through your physical card), you should see an IPv4 address being returned by Request.UserHostAddress
The 4 Guys from Rolla website has a solution here, which I ve used in my app.
Update:
Just in case this link goes dead, here is code based on this link:
public string GetIpAddress()
{
string ipAddressString = HttpContext.Current.Request.UserHostAddress;
if (ipAddressString == null)
return null;
IPAddress ipAddress;
IPAddress.TryParse(ipAddressString, out ipAddress);
// If we got an IPV6 address, then we need to ask the network for the IPV4 address
// This usually only happens when the browser is on the same machine as the server.
if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
{
ipAddress = System.Net.Dns.GetHostEntry(ipAddress).AddressList
.First(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork);
}
return ipAddress.ToString();
}
Go to Start -> click on Control Panel -> click on View network status and tasks
in Control Panel window -> click on change adapter settings
in Network and Sharing Center
window.
Network Connections
window will appear. Here you right click on the network adapter
(can be wireless adapter or wired Ethernet adapter) that you wish to disable IPv6 and click Properties
.
In the network adapter properties
window, untick Internet Protocol Version 6 (TCP/IPv6)
and click OK.
Type regedit
in command prompt to launch registry editor, proceed to locate following registry item in Registry editor.
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpip6ParametersDisabledComponents
If the DisabledComponents
item is unavailable, you must create it in following format by going to Edit -> New -> DWORD (32-bit) Value and set the value to 0xffffffff
(just type ffffffff
). This will disable all IPv6 features except the IPv6 loopback interface, finally click OK
.
Restart the computer.
In my webpages I have references to js and images as such: "../../Content/Images/"Filename" In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename" 1-...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
I m looking for best practices here. Sorry. I know it s subjective, but there are a lot of smart people here, so there ought to be some "very good" ways of doing this. I have a custom object called ...
I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...
i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...
For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!