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?
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();
}