Scu*_*iad 3 c# ssl asp.net-web-api kestrel-http-server
我正在尝试使用 https 和 .Net Web API 设置一个简单的 API。
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseKestrel(options =>
{
string key = {{private.key}} //is this the password it wants?
options.Listen(IPAddress.Any, 50790);
options.Listen(IPAddress.Any, 40354, listenOptions =>
{
listenOptions.UseHttps("certificate.crt", key);
});
})
.Build();
}
//{{private.key}} is the private key in a string.
Run Code Online (Sandbox Code Playgroud)
在启动和连接 http 时使用它可以正常工作,但是一旦我尝试使用 https,我就会收到巨大的错误并且没有响应发送到客户端。
从让我们加密得到一个证书:ca_bundle.crt、certificate.crt 和 private.key。
这是我尝试使用 https 连接时遇到的错误:
失败:Microsoft.AspNetCore.Server.Kestrel[0] 从 IConnectionAdapter 的 OnConnectionAsync 方法未捕获异常。System.NotSupportedException:服务器模式 SSL 必须使用具有关联私钥的证书。在 System.Net.Security.SecureChannel.AcquireServerCredentials(Byte[]& thumbPrint) 在 System.Net.Security.SecureChannel.GenerateToken(Byte[] input, Int32 offset, Int32 count, Byte[]& output) 在 System.Net。 System.Net.Security.SslState.StartSendBlob(Byte[] 传入, Int32 计数, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.ProcessReceivedBlob( Byte[] 缓冲区,Int32 计数,AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.StartReadFrame(Byte[] 缓冲区,Int32 readBytes,
我怎样才能让它工作?