ASP.NET Core Kestrel 中使用 HTTPS (SSL)
2016-08-16 16:29
706 查看
在ASP.NET Core中,如果在Kestrel中想使用HTTPS对站点进行加密传输,可以按照如下方式
然后命令行窗口运行
申请证书
这一步就不详细说了,有免费的和收费的,申请完成之后会给你一个*.pfx结尾的文件。
添加NuGet包
nuget中查找然后再程序中添加引用Microsoft.AspNetCore.Server.Kestrel.Https
配置
把*.pfx结尾的文件拷贝的程序的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); }; } }
然后命令行窗口运行
dotnet xxx.dll --server.urls https://www.example.com:port[/code]即可。
本文地址:http://www.cnblogs.com/savorboard/p/aspnetcore-kestrel-https.html
作者博客:Savorboard
欢迎转载,请在明显位置给出出处及链接
相关文章推荐
- ASP.NET Core Kestrel 中使用 HTTPS (SSL)
- ASP.NET Core Kestrel 中使用 HTTPS (SSL)
- ASP.NET Core Kestrel 中使用 HTTPS (SSL)
- ASP.NET Core Kestrel 中使用 HTTPS (SSL)
- ASP.NET Core Kestrel 中使用 HTTPS (SSL)
- 在 ASP.NET MVC 中使用 HTTPS (SSL/TLS)
- ASP.NET Core Kestrel部署HTTPS
- Windows IIS ASP.NET Core中创建和使用HTTPS自签名证书
- 项目开发中的一些注意事项以及技巧总结 基于Repository模式设计项目架构—你可以参考的项目架构设计 Asp.Net Core中使用RSA加密 EF Core中的多对多映射如何实现? asp.net core下的如何给网站做安全设置 获取服务端https证书 Js异常捕获
- 在 ASP.NET MVC 中使用 HTTPS (SSL/TLS)
- 在 ASP.NET MVC 中使用 HTTPS (SSL/TLS)
- 在 ASP.NET MVC 中使用 HTTPS (SSL/TLS) -- 学习
- 在 ASP.NET MVC 中使用 HTTPS (SSL/TLS)
- ASP.NET Core Kestrel部署HTTPS
- ASP.NET Core 使用 URL Rewrite 中间件实现 HTTP 重定向到 HTTPS
- ASP.NET Core 1.0 中使用Log日志
- 避免在ASP.NET Core中使用服务定位器模式
- 结合Jexus + Kestrel 部署 asp.net core 生产环境
- ASP.NET Core 使用 Redis 和 Protobuf 进行 Session 缓存
- ASP.NET Core 1.0 中 EntityFramework 与 PostgreSQL 的使用