關於.net core https支援的整理
參考:
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.程式碼配置
varx509ca=newX509Certificate2(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證書路徑