title: How to write Request.ServerVariables["HTTP_X_FORWARDED_FOR"] in ASP.NET Core?
body: <p>Hi i am using the following line of code in mvc application working fine.</p>
  
  <blockquote>
    <p>Request.ServerVariables["HTTP_X_FORWARDED_FOR"]</p>
  </blockquote>
  
  <p>How to get ipaddress in asp.net core. I wrote the following code in asp.net core but it always returns null.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> protected string GetClientIPAddress()
          {
  #if DEBUG
              return _configuration.GetSection("IPAddress")?.Value;
  #else
              string ipAddress = string.Empty;
              if (Request.HttpContext.Connection.RemoteIpAddress != null)
              {
                  ipAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();
              }
              return ipAddress;
  #endif
          }</code></pre>
  </div>
  </div>
  </p>