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.