Answers for "how to get client ip address in c#"

C#
1

Request.ServerVariables["HTTP_X_FORWARDED_FOR"] get only one ipaddress

private string GetUserIP()
{
  string ipList = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

  if (!string.IsNullOrEmpty(ipList))
  {
    return ipList.Split(',')[0];
  }

  return Request.ServerVariables["REMOTE_ADDR"];
}
Posted by: Guest on June-10-2020
0

get client ip address c#

//get client ip address
Public string GetIp()
{
string ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(ip))
{
ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
  return ip;
}
Posted by: Guest on April-10-2021

Code answers related to "how to get client ip address in c#"

C# Answers by Framework

Browse Popular Code Answers by Language