Wednesday, October 30, 2019

Using HTTPS in the ASPNETCORE development server Kestrel

To use SSL with the ASP.net Core development server, Kestrel, first export your certificate to a PFX file. Add the file to your project and then add the following section to your csproj:

  <ItemGroup>
    <None Update="mydomain.pfx">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

This addition will cause the PFX to be coped to your output directory. After adding this to your csproj, add the following section to your appsettings.json file to use the exported certificate:

"Kestrel": {
    "Endpoints": {
        "HttpsInlineCertFile": {
            "Url": "https://test.mydomain.com",
            "Certificate": {
                "Path": "mydomain.pfx",
                "Password": "mypfxpassword"
            }
        }
    }
}

Poof, you're secure.