LiS LiS - 1 year ago 133
ASP.NET (C#) Question

IPAddress of a login system

Using the bellow code .

protected string GetUserIP()
string strUserIP = string.Empty;
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
strUserIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
strUserIP = HttpContext.Current.Request.UserHostAddress;
return strUserIP;

i get the IPaddress like the format

How do I get the correct IP address of a system.

Answer Source

It is of localhost ::1 if you use on web server you will get the correct one.

Though it will depend on the configuration of the network from where the user is accessing your application.

There can be firewall which doesn't expose the actual IP of the client system.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download