Kestrel UseHttps()方法签名在.net core 2中更改

Pet*_*ter 10 asp.net-core

我编写了一个基于.NET核心1.1的ASP.NET应用程序.此应用程序按预期工作.今天,我刚刚升级了我的服务器dotnet-sdk-2.0.0-preview2-006497并对.csproj文件进行了必要的更改.

在我的应用程序的main方法中,我有以下代码:

 var host = new WebHostBuilder()
    .UseKestrel(options => {
       options.UseHttps("MyCert.pfx");
    })
    ...
Run Code Online (Sandbox Code Playgroud)

此代码曾经在.net core 1.0下运行良好,但在.net core 2.0下出现错误.

KestrelServerOptions does not contain a definition for UseHttps and
the best extension method overload
ListenOptionsHttpsExtensions.UseHttps(ListenOptions, string) requires
a receiver of type ListenOptions
Run Code Online (Sandbox Code Playgroud)

我想知道如何解决这个问题.我可以null作为参数传递吗?问候.

Mat*_*att 19

这是一个突破性的变化,看到这个公告,重要的是:

.Listen()没有重载,允许您在不使用选项lambda的情况下配置SSL证书.

换句话说,您只能在一些监听选项中添加HTTPS.最简单的替代方案是:

var host = new WebHostBuilder()
    .UseKestrel(options =>
        options.Listen(IPAddress.Any, 443, listenOptions =>
                listenOptions.UseHttps("MyCert.pfx")))
        ...
Run Code Online (Sandbox Code Playgroud)

所以你说使用端口443监听任何分配的IP.