title: To get current ip address in c# from client side
body: <p>In my application,i need to get the ip address of user who loads the application </p>
  
  <p>I tried various way to get ip address.But when try to load application ,not getting current ip address.</p>
  
  <pre><code> protected string GetIPAddress()
      {
          System.Web.HttpContext context = System.Web.HttpContext.Current;
          string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  
          if (!string.IsNullOrEmpty(ipAddress))
          {
              string[] addresses = ipAddress.Split(',');
              if (addresses.Length != 0)
              {
                  return addresses[0];
              }
          }
  
          return context.Request.ServerVariables["REMOTE_ADDR"];
      }
  
  string ipAddress=Dns.GetHostEntry(Dns.GetHostName()).AddressList.Where(o =&gt; o.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).First().ToString()
  
  string ipAddress=(HttpContext.Current.Request.UserHostAddress != null) ? HttpContext.Current.Request.UserHostAddress : null;
  
  
  
  
    using (WebClient wc = new WebClient())
          {
              ipAddress = wc.DownloadString("https://api.ipify.org/");
          }
  </code></pre>