Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How ASP.NET Core Kestrel deploys HTTPS

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

ASP.NET Core Kestrel how to deploy HTTPS, many novices are not very clear, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

ASP.NET Core configures Kestrel deployment HTTPS. Now that most websites have deployed HTTPS, people pay more and more attention to security.

Today, a brief introduction to ASP.NET Core deployment HTTPS, directly through the configuration of Kestrel. You can also deploy HTTPS through the front Nginx.

Let's get straight to the point.

Create a new project and add references

Create a new ASP.NET Core Web Application template and select empty.

Create a new project and add a reference to Microsoft.AspNetCore.Server.Kestrel.Https.

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

If your .NET Core SDK is still 1. 0, add the version number Install-Package Microsoft.AspNetCore.Server.Kestrel.Https-Version 1.0.0 when referencing.

Generate a certificate

Generate certificates through OpenSSL

You must first make sure that OpenSSL is installed.

First of all, create your own root certificate root and do your own 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 server.csr-out server.crt

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

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

Copy server.pfx to the project root

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 () .build (); host.Run ();}}

Then choose to run using Kestrel.

Open a browser and enter https://localhost/

Since the certificate is generated by itself, the red flag is displayed, that is, it has not been verified.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report