Use HTTPS (SSL) and kestrelssl in ASP. NET Core Kestrel

Source: Internet
Author: User

Use HTTPS (SSL) and kestrelssl in ASP. NET Core Kestrel

In ASP. NET Core, If You Want To Use HTTPS for encrypted transmission of the site in Kestrel, you can follow the method below

Apply for Certificate 

This step is not detailed. If there are free and charged items, you will be given a file at the end of *. pfx after the application is completed.

Add NuGet package

Find the file in nuget and add the reference Microsoft. AspNetCore. Server. Kestrel. Https to the program.

Configuration

Copy the file at the end of *. pfx to the Web root directory of the program, and then modify the Programs. cs file:

Public class Program {public static void Main (string [] args) {var config = new ConfigurationBuilder (). addCommandLine (args ). addEnvironmentVariables ("ASPNETCORE _"). build (); var host = new WebHostBuilder (). useConfiguration (config ). useKestrel (ConfigHttps ()). useContentRoot (Directory. getCurrentDirectory ()). useIISIntegration (). useStartup <Startup> (). build (); host. run ();} private static Action <KestrelServerOptions> ConfigHttps () {return x =>{ var pfxFile = Path. combine (Directory. getCurrentDirectory (),"*. pfx "); // enter the applied key var certificate = new X509Certificate2 (pfxFile," password "); x. useHttps (certificate );};}}

Then run dotnet xxx. dll -- server. urls https://www.example.com: port in the command line window.

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.