首页 > 技术文章 > netcore配置https协议

zwbsoft 2022-03-12 09:29 原文

1、在program.cs文件中添加如下代码:

           webBuilder.ConfigureKestrel(options =>
                    {
                        var ip = IPAddress.Parse(AppSettings.app(new string[] { "https", "ip" }));
                        int port = int.Parse(AppSettings.app(new string[] { "https", "port" }));
                        string pfxPath = AppSettings.app(new string[] { "https", "pfxPath" });
                        string pfxPassword = AppSettings.app(new string[] { "https", "pfxPassword" });
                        options.Listen(ip, port, listenOptions =>
                        {
                            listenOptions.Protocols = HttpProtocols.Http2;
                            listenOptions.UseHttps(pfxPath, pfxPassword);
                        });
                    });

2、appsetting.json配置如下:

"https": {
    "ip": "192.168.40.10",
    "port": "8080",
    "pfxPath": "C:/Users/admin/Downloads/SHA256withRSA_m.sythams.com(1).pfx",
    "pfxPassword": ""
  }

  

推荐阅读