53

I am trying to get client ip address using

    HttpContext.Request.UserHostAddress;

but it returns ::1.

How to solve this?

user2771704
  • 5,204
  • 6
  • 33
  • 38
yohan.jayarathna
  • 3,263
  • 13
  • 53
  • 73

4 Answers4

54

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

Community
  • 1
  • 1
V4Vendetta
  • 34,000
  • 7
  • 73
  • 81
29

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.

Eamon Nerbonne
  • 43,645
  • 18
  • 92
  • 161
4

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!

FranciscoBouza
  • 517
  • 6
  • 18
2

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

Rajat Singh
  • 83
  • 10