Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 从appsettings.json加载SSL证书_Linux_Ssl_Asp.net Core_Raspberry Pi3_Kestrel - Fatal编程技术网

Linux 从appsettings.json加载SSL证书

Linux 从appsettings.json加载SSL证书,linux,ssl,asp.net-core,raspberry-pi3,kestrel,Linux,Ssl,Asp.net Core,Raspberry Pi3,Kestrel,我构建了一个.NETCore2.2应用程序,正在加载到raspberry pi上。我使用Kestrel托管web服务。在pi上,我创建了一个自分配的certificate.pfx。如果我在应用程序a.UseHttps中硬编码证书名和密码,浏览器可以找到它 但是,如果我在代码中对其进行注释并使用appsettings.json文件(我希望它位于appsettings.json中,以便客户端可以上载自己的证书),则重定向到Https将起作用,但证书未加载,页面无法连接 这是我用来配置appsetti

我构建了一个.NETCore2.2应用程序,正在加载到raspberry pi上。我使用Kestrel托管web服务。在pi上,我创建了一个自分配的certificate.pfx。如果我在应用程序a.UseHttps中硬编码证书名和密码,浏览器可以找到它

但是,如果我在代码中对其进行注释并使用appsettings.json文件(我希望它位于appsettings.json中,以便客户端可以上载自己的证书),则重定向到Https将起作用,但证书未加载,页面无法连接

这是我用来配置appsettings.json文件的文档:

证书位于应用程序文件夹中

目前,我已经在应用程序中注释了这段代码,但是当代码没有注释时,它确实可以工作。我希望通过appsettings.json文件来设置这些相同的设置

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .ConfigureKestrel((context, options) =>
                {                   
                    /*options.Listen(IPAddress.Any, 80);*/         // http:*:80                 
                    //options.Listen(IPAddress.Any, 5001, listenOptions =>
                    //{
                    //  listenOptions.UseHttps("certificate.pfx", "password");
                    //});
                });

这篇文章最终得到了我需要的解决方案:

更准确地说,这是文章标题为“在ASP.NET Core 2.0中配置HTTPS”的部分

我没有使用appsettings.json,而是创建了一个名为certificate.json的新json文件


然后,我将certificate.json中的证书名和密码输入到program.cs代码中。

从文档中,
将AllowInvalid设置为true,以允许使用无效证书(例如,自签名证书)。
,您可以尝试使用证书存储字段指定证书吗?或者您可以使用program.cs中的配置,请参阅
{
  "https_port": 5001,
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  },
  "AllowedHosts": "*",
  "AllowInvalid": true,
  "Kestrel": {
    "Endpoints": {
      "Http": {
        "Url": "http://*:80"
      }
    },
    "Https": {
      "Url": "https://*:5001",
      "Certificate": {
        "Path": "certificate.pfx",
        "Password": "password"
      }
    }
  }
}