title: Enable HTTPS secure connection for Asp.net core web api
body: <p>I have REST API application created using ASP.NET Core 2.1. REST API is created by WebHostBuilder and hosted by Kestrel. </p>
  
  <pre><code>Startup.Kernel = kernel;
      _restApiServer = new WebHostBuilder()
        .UseKestrel(options =&gt;
        {
  
        })
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup&lt;Startup&gt;()
        .UseUrls(string.Format("http://localhost:{0}", _configuration.PortNumber))
        .UseSetting("https_port",_configuration.HttpsPort.ToString())
        .Build();
       _restApiServer.Run();
  </code></pre>
  
  <p>REST API is served on port 8998 by default. This REST API is started by my different application. I am able to connect to this REST API using browser and POSTMAN. </p>
  
  <p>Now I would like to secure my connection to REST API. What I did is:
  I've added necessity configuration to force secure connection in my Startup class in Configure method:</p>
  
  <pre><code>app.UseHttpsRedirection();
  </code></pre>
  
  <p>And I've also executed a code for trusting dev certs:</p>
  
  <pre><code>dotnet dev-certs https --trust
  </code></pre>
  
  <p>The case is that when I try to access the web api via browser I get and error:</p>
  
  <blockquote>
    <p>localhost refused to connect.
    Try:</p>
    
    <p>Checking the connection</p>
    
    <p>Checking the proxy and the firewall</p>
    
    <p>ERR_CONNECTION_REFUSED</p>
  </blockquote>
  
  <p>Also when I am using POSTMAN to call some REST API methods I got and error:</p>
  
  <blockquote>
    <p>Could not get any response</p>
  </blockquote>
  
  <p>What am I doing wrong? Do I need to specify the certificate directly in Kestrel configuration?</p>