asp.net Core Kestrel using HTTPS (SSL) _ Practical Tips

Source: Internet
Author: User
Tags file copy pfx file

In ASP.net core, if you want to use HTTPS to encrypt a site in Kestrel, you can

Request a certificate

This step is not detailed, there are free and charge, the application will be completed after the end of a *.pfx file.

Add NuGet Package

NuGet and then add references in the program Microsoft.AspNetCore.Server.Kestrel.Https

Configuration

Put the *.pfx end of the file copy of the program's Web root directory, 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");
    Password fill in the requested key
    var certificate = new X509Certificate2 (pfxfile, "password");
    X.usehttps (certificate);
   };
  }
  

The command Line window then runs dotnet xxx.dll--server.urls https://www.example.com:port.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.