ASP.NET Core Kestrel 中使用 HTTPS (SSL)
生活随笔
收集整理的這篇文章主要介紹了
ASP.NET Core Kestrel 中使用 HTTPS (SSL)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在ASP.NET Core中,如果在Kestrel中想使用HTTPS對站點(diǎn)進(jìn)行加密傳輸,可以按照如下方式
申請證書
這一步就不詳細(xì)說了,有免費(fèi)的和收費(fèi)的,申請完成之后會給你一個*.pfx結(jié)尾的文件。
添加NuGet包
nuget中查找然后再程序中添加引用Microsoft.AspNetCore.Server.Kestrel.Https
配置
把*.pfx結(jié)尾的文件拷貝的程序的Web根目錄,然后修改Programs.cs文件:
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 填寫申請的密鑰var certificate = new X509Certificate2(pfxFile, "password");x.UseHttps(certificate);};}}
然后命令行窗口運(yùn)行dotnet xxx.dll --server.urls https://www.example.com:port即可。
原文地址:http://www.cnblogs.com/savorboard/p/aspnetcore-kestrel-https.html
.NET社區(qū)新聞,深度好文,微信中搜索dotNET跨平臺或掃描二維碼關(guān)注
總結(jié)
以上是生活随笔為你收集整理的ASP.NET Core Kestrel 中使用 HTTPS (SSL)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 你知道C#中的Lambda表达式的演化过
- 下一篇: asp.net ajax控件工具集 Au