zoukankan      html  css  js  c++  java
  • ASP.NET Core Kestrel 中使用 HTTPS (SSL)

    在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即可。


    本文地址:http://www.cnblogs.com/savorboard/p/aspnetcore-kestrel-https.html
    作者博客:Savorboard
    欢迎转载,请在明显位置给出出处及链接

  • 相关阅读:
    ZOJ2913Bus Pass(BFS+set)
    HDU1242 Rescue(BFS+优先队列)
    转(havel 算法)
    ZOJ3761(并查集+树的遍历)
    ZOJ3578(Matrix)
    HDU1505
    ZOJ3574(归并排序求逆数对)
    VUE-脚手架搭建
    VUE脚手架搭建
    VUE-node.js
  • 原文地址:https://www.cnblogs.com/savorboard/p/aspnetcore-kestrel-https.html
Copyright © 2011-2022 走看看