Getting the end user id address in asp.net

Sheonarayan
Posted by Sheonarayan under ASP.NET category on | Points: 40 | Views : 2142
To get the end user's IP address, call this function.

protected string GetUserIPAddresss()
{
string ip = string.Empty;
if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
}
else if (Request.UserHostAddress.Length != 0)
{
ip = Request.UserHostAddress;
}
else
{
ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
return ip;
}


Thanks

Comments or Responses

Login to post response