NET Core Kestrel deploying HTTPS using SSL Certificates

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.