I am trying to get the IP address of the user who is browsing the website, might be through mobile phones or PC. I have tried using a set of code, but what I get back is ::1
, may I know if this is wrong or it's meant to be like that?
private string GetUser_IP()
{
string VisitorsIPAddr = string.Empty;
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
VisitorsIPAddr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
{
VisitorsIPAddr = HttpContext.Current.Request.UserHostAddress;
}
ipAddress = VisitorsIPAddr;
return ipAddress;
}
Thank you for the help in advance.