參考:
https://blog.walterlv.com/post/add-https-support-for-asp-dotnet
https://www.cnblogs.com/yaopengfei/p/12057979.html
https://blog.walterlv.com/post/add-https-support-for-asp-dotnet-using-kestrel
https://www.cnblogs.com/TianFang/p/13659522.html
https://www.cnblogs.com/linezero/p/aspnetcorehttps.html
.net core 下配置https證書
默認使用 .net core sdk自帶的dotnet dev-certs的方式
為了在開發環境中使用HTTPS,必須要生成加密證書。.net core提供了一個全局工具dotnet-dev-certs,使用該工具可在本地環境中創建自簽名的證書。可以通過下面命令行安裝該工具:
創建證書 如:
-ep標志表示將生成證書導出的存儲目錄;
-p標志表示生成證書的密碼。
dotnet dev-certs https -ep E:\123.pfx -p 123456789
信任證書
dotnet dev-certs https --trust
1.代碼配置
var x509ca = new X509Certificate2(File.ReadAllBytes(@"r:\tianfang.pfx"), "tianfang");
webBuilder.UseKestrel(option => option.ListenAnyIP(3000, config => config.UseHttps(x509ca)));
或
2.環境變量
ASPNETCORE_Kestrel__Certificates__Default__Password=證書密碼
ASPNETCORE_Kestrel__Certificates__Default__Path=HTTPS證書路徑
