title: How to access server variables in ASP.Net Core 2.x
body: <p>I m using ASP.Net core 2.0 web app and it is deployed on Azure. What I need to do is to get client IP Address. For this, I m searching all over the internet and found that the server variables help me on this.</p>
  <p>So I found this code from <a href="https://forums.asp.net/t/2071140.aspx?%20beta8%20How%20to%20get%20client%20IP%20in%20controller%20action%20" rel="noreferrer">here</a> to get Client IP using:</p>
  <p><code>string IpAddress = this.Request.ServerVariables[&quot;REMOTE_ADDR&quot;];</code></p>
  <p>But when I'm trying above code it shows me an error &quot;HttpRequest does not contain a definition for Server Variables&quot;</p>
  <p>Also I was try this code:</p>
  <pre><code>var ip0 = HttpContext.Features.Get&lt;IHttpConnectionFeature&gt;()?.RemoteIpAddress;
  </code></pre>
  <p>Code Definition</p>
  <blockquote>
  <p><strong>RemoteIpAddress</strong> The IP Address of the client making the request. Note this may be for a proxy rather than the end user.</p>
  </blockquote>
  <p>Above code is getting the IP address but it is not a clientip and each time when I access above code via controller it refreshes the IP. Maybe this is an Azure web service proxy which makes get request each time.</p>
  <p>What is the right way to access server variables in ASP.Net Core 2.x?</p>