minimal-apisasp.net-core-8

,Net Core 8Minimal API Self signed SSL deployment


I can do it with OpenSSL, but need to deploy this self signed certificate to many PCs, so that the web browser can communicate to a localhost executable. I can't ask each and every PC to install openssl.

Here is what I did:

  1. In powershell

    New-SelfSignedCertificate -CertStoreLocation Cert:\LocalMachine\My -DnsName "localhost" -FriendlyName "localhost" -NotAfter (Get-Date).AddYears(10)

  2. Launch Manage computer certificates

  3. Navigate to Certificates - Local Computer > Personal > Certificates to find your newly created certificate.

  4. Copy the certificate and paste it into Trusted Root Certification Authorities > Certificates.

  5. Then export the certificate with private key to a pfx file (example: localhost.pfx)

  6. The setup

    services.AddHttpsRedirection(options => { options.HttpsPort = Port; });

    app.UseHttpsRedirection();

Question: how can I load the PFX into my Dotnet Core 8 Minimal API app?


Solution

  • As far as I know there is no difference in this regard between MVC and minimal API. Overall check this link and find "Specify HTTPS using a custom certificate" section.