title: Load an SSL certificate from appsettings.json
body: <p>I built a .NET core 2.2 application, that I am loading onto a raspberry pi. I am hosting the web service using Kestrel. On the pi, I have created a self-assigned certificate.pfx. If I hard code into the application a .UseHttps with the certificate name and password, the browser can find it.</p>
  
  <p>However, if I comment it out of the code and use the appsettings.json file instead (I would like it in the appsettings.json, so clients can upload their own certificates), the redirect to Https will work, but the certificate is not loading and the page fails to connect.</p>
  
  <p>This is the document I have been using to configure my appsettings.json file:
  <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.2" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.2</a></p>
  
  <p>The certificate is located in the application folder.</p>
  
  <p>Currently I have this code commented out of the application, but it does work when the code is not commented. I am hoping to set up these same settings through the appsettings.json file instead.</p>
  
  <pre><code>public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
              WebHost.CreateDefaultBuilder(args)
                  .UseStartup&lt;Startup&gt;()
                  .ConfigureKestrel((context, options) =&gt;
                  {                   
                      /*options.Listen(IPAddress.Any, 80);*/         // http:*:80                 
                      //options.Listen(IPAddress.Any, 5001, listenOptions =&gt;
                      //{
                      //  listenOptions.UseHttps("certificate.pfx", "password");
                      //});
                  });
  </code></pre>
  
  <p>here is the appsettings.json file:</p>
  
  <pre><code>{
    "https_port": 5001,
    "Logging": {
      "LogLevel": {
        "Default": "Warning"
      }
    },
    "AllowedHosts": "*",
    "AllowInvalid": true,
    "Kestrel": {
      "Endpoints": {
        "Http": {
          "Url": "http://*:80"
        }
      },
      "Https": {
        "Url": "https://*:5001",
        "Certificate": {
          "Path": "certificate.pfx",
          "Password": "password"
        }
      }
    }
  }
  </code></pre>