ASP. NET core Configuration Kestrel deploy HTTPS. Now most of the sites have been deployed HTTPS, we are increasingly concerned about security.
Today, a brief introduction to ASP. NET Core deploys HTTPS, directly by configuring Kestrel. You can also deploy HTTPS via the front-facing nginx.
The following goes straight to the chase.
Create a new project and add a reference
Create a new ASP. NET Core Web application template Select empty.
Create a new project Add Reference Microsoft.AspNetCore.Server.Kestrel.Https.
Install-package Microsoft.AspNetCore.Server.Kestrel.Https
If your. NET Core SDK is still 1.0, then the reference is prefixed with the version number Install-package microsoft.aspnetcore.server.kestrel.https-version 1.0.0
Generate certificate
Generate certificates with OpenSSL
You must first ensure that OpenSSL is installed.
Start by creating your own root certificate root yourself as the CA that is the publisher.
OpenSSL genrsa-des3-out Root.key
Then follow the prompts to enter the password
OpenSSL Req-new-key root.key-out ROOT.CSR
Enter the password you just set, and then fill in some information
Then create a 10-year root certificate root.crt
OpenSSL x509-req-days 3650-sha1-extensions v3_ca-signkey root.key-in root.csr-out root.crt
Create a server certificate
OpenSSL genrsa-des3-out Server.key 2048
OpenSSL Req-new-key server.key-out server.req
OpenSSL x509-req-days 730-sha1-extensions v3_req-ca root.crt-cakey root.key-caserial root.srl-cacreateserial-in s Erver.csr-out SERVER.CRT
OpenSSL pkcs12-export-in Server.crt-inkey server.key-out server.pfx
The final server.pfx is the one that can be used to configure HTTPS.
Copy the server.pfx to the project root directory
Add a NuGet package
Find in NuGet and then add references in the programMicrosoft.AspNetCore.Server.Kestrel.Https
Then open the Program.cs change code as follows:
public class program {public static void Main (string[] args) { var host = new Webhostbuilder () . Usekestrel (option=> { option. UseHttps ("server.pfx", "Linezero"); }) . Useurls ("https://*:443") . Usecontentroot (Directory.GetCurrentDirectory ()) . Useiisintegration () . Usestartup<startup> () . Build (); Host. Run (); } }
Then select Run with Kestrel.
Open Browser Input https://localhost/
Because the certificate is generated by itself, the red label is not verified.
Test certificate Download: server.pfx
NET Core Kestrel deploying HTTPS using SSL Certificates