title: ASP.NET Core 2.1 get current web hostname and port in Startup.cs
body: <p>I want to register my WebAPI to Consul service discovery and for that I should provide URL of my WebAPI (for example: <a href="http://service1.com" rel="noreferrer">http://service1.com</a>) and health check endpoint (<a href="http://service1.com/health/check" rel="noreferrer">http://service1.com/health/check</a>). How can I get that URL? </p>
  
  <p>I found this piece of code:</p>
  
  <pre><code>var features = app.Properties["server.Features"] as FeatureCollection;
  var addresses = features.Get&lt;IServerAddressesFeature&gt;();
  var address = addresses.Addresses.First();               
  var uri = new Uri(address);
  </code></pre>
  
  <p>It returns 127.0.0.1:16478 instead of localhost:5600. I think first one used by dotnet.exe and second one is IIS which forwards 5600 to 16478. How can I get localhost:5600 in Startup.cs?</p>