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.