Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to get client ip address using

    HttpContext.Request.UserHostAddress;

but it returns ::1.

How to solve this?

like image 570
yohan.jayarathna Avatar asked Jun 20 '11 09:06

yohan.jayarathna


3 Answers

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

like image 195
V4Vendetta Avatar answered Nov 20 '22 13:11

V4Vendetta


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.

like image 36
Eamon Nerbonne Avatar answered Nov 20 '22 14:11

Eamon Nerbonne


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!

like image 4
FranciscoBouza Avatar answered Nov 20 '22 13:11

FranciscoBouza