Deploying HTTPS and kestrelhttps in ASP. NET Core Kestrel

Source: Internet
Author: User
Tags install openssl openssl x509

Deploying HTTPS and kestrelhttps in ASP. NET Core Kestrel

ASP. NET Core: Configure Kestrel to deploy HTTPS. Now, HTTPS has been deployed on most websites, and everyone is paying more and more attention to security.

Today, we will briefly introduce how to deploy HTTPS in ASP. NET Core by configuring Kestrel. You can also deploy HTTPS through pre-Nginx.

Next, go to the topic.

Create a project and add reference

Create an ASP. NET Core Web Application Template and select null.

Create a project and add Microsoft. AspNetCore. Server. Kestrel. Https.

Install-Package Microsoft.AspNetCore.Server.Kestrel.Https

If your. NET Core SDK is still 1.0, add the Version Install-Package Microsoft. AspNetCore. Server. Kestrel. Https-Version 1.0.0 to the reference.

Generate Certificate

Generate a certificate using OpenSSL

You must first install OpenSSL.

First, create your own root certificate root and make your own CA, that is, the issuer.

Openssl genrsa-des3-out root. key

Enter the password as prompted.

Openssl req-new-key root. key-out root. csr

Enter the password you just set and enter 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 server.csr -out server.crt


openssl pkcs12 -export -in server.crt -inkey server.key -out server.pfx

 

The final server. pfx can be used to configure HTTPS.

Copy server. pfx to the project root directory.

 

Then open Program. cs and change the 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 choose to run with Kestrel.

Open your browser and enter https: // localhost/

 

Because the certificate is generated by yourself, the red mark is displayed, that is, the certificate is not verified.

Download the test certificate: server. pfx

 

If you think this article is helpful to you, click"Recommendation", Thank you.

 

Related Article

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.