title: Public ip address to get country in web api
body: <p>I'm trying to get a user's country based on IP address in web api. Using userhostaddress it returns a Private IP not their public IP.</p>
  
  <p>This is what I've been trying:</p>
  
  <pre><code>string clientAddress = HttpContext.Current.Request.UserHostAddress;
  string nowip = null;
  nowip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  if (string.IsNullOrEmpty(nowip)){
      nowip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
  }
  
  WebRequest request = WebRequest.Create("http://checkip.dyndns.org");
  WebResponse response = request.GetResponse();
  StreamReader stream = new StreamReader(response.GetResponseStream());
  string ipAddress = stream.ReadToEnd();
  </code></pre>