Request.UserHostAddress issue with return result "::1"

C#asp.net MvcIpHttpcontext

C# Problem Overview


I am trying to get client ip address using

    HttpContext.Request.UserHostAddress;

but it returns ::1.

How to solve this?

C# Solutions


Solution 1 - C#

::1 is for localhost, Maybe this might be useful.

Solution 2 - C#

This is not a bug - you're connecting from localhost on an IPv6 enabled machine. ::1 is the loopback address - a double colon means "omitted zeroes", so this address corresponds to address 1.

If you're developing new software, I'd urge you not to disable IPv6. The easiest time to implement support is right from the start, and spending time on workarounds is perhaps just wasting effort putting off the inevitable.

Solution 3 - C#

Although it's true that this is not a bug, maybe you can check this link, where your problem is nicely described and "solved". It says that the way the issue behaves depends on the operating system, since a user fixed some problems in an application running in Windows Server 2008 by commenting the ::1 line in the hosts file, while he had to uncomment it in Windows 7.

Hope you managed to solve that! Good luck!

Solution 4 - C#

it is not bug actually you are running your application on local host it is just giving you the ip of of local host and it is ipv6 format

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionyohan.jayarathnaView Question on Stackoverflow
Solution 1 - C#V4VendettaView Answer on Stackoverflow
Solution 2 - C#Eamon NerbonneView Answer on Stackoverflow
Solution 3 - C#FranciscoBouzaView Answer on Stackoverflow
Solution 4 - C#Rajat SinghView Answer on Stackoverflow