title: How to allow HTTPS connections from both localhost and container towards an ASP.NET Core Web API application?
body: <p>I am trying to use Docker for an existing application and I have the following issue. When the API is trying to get the Identity Server metadata from the container, it fails with the following:</p>
  
  <pre><code>web_api          | System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'https://host.docker.internal:5500/.well-known/openid-configuration'.
  web_api          |  ---&gt; System.IO.IOException: IDX20804: Unable to retrieve document from: 'https://host.docker.internal:5500/.well-known/openid-configuration'.
  web_api          |  ---&gt; System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
  web_api          |  ---&gt; System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure. 
  </code></pre>
  
  <p>This is indeed confirmed by the host browser (certification error in Chrome).</p>
  
  <p>If I access the same metadata using localhost instead of host.docker.internal, it works as expected.</p>
  
  <p>I have used the instructions from <a href="https://docs.microsoft.com/en-us/aspnet/core/security/docker-compose-https?view=aspnetcore-3.1" rel="noreferrer">here</a> in order to create and trust a localhost certificate that it is also used by the identity server:</p>
  
  <pre><code>dotnet dev-certs https -ep %USERPROFILE%\.aspnet\https\aspnetapp.pfx -p { password here }
  dotnet dev-certs https --trust
  </code></pre>
  
  <p>I assume these instructions create the certificate only for localhost, but I am trying to get a solution that also works for host.docker.internal.</p>
  
  <p><strong>Question:</strong> How to allow HTTPS connections from both localhost and container towards an ASP.NET Core Web API application?</p>