如何使用Kestrel托管.NET核心应用程序?

时间:2020-02-05 16:05:33

标签: .net-core kestrel

我有一个从模板构建的.NET Core Web服务。当我从Visual Studio运行它时,它使用了Kestrel主机,正如我期望的那样(请参见下面的配置)。但是,当我发布它时,它可以在IIS中运行。我读过的所有内容都说我应该可以在Kestrel中托管.NET Core应用程序,但是我似乎无法说服发布者使用Kestrel作为主机来部署它。

AppSettings.Production.json

{
  "Kestrel": {
    "Endpoints": {
      "localhostHttps": {
        "Port": "443",
        "Url": "https://production.thetarex.com",
        "Certificate": {
          "Subject": "www.thetarex.com",
          "Store": "My",
          "Location": "LocalMachine",
          "AllowInvalid": "false"
        }
      }
    }
  },
}

startup.cs

    public static void Main(string[] args)
    {
        IHost webHost = CreateHostBuilder(args).Build();
        var logger = webHost.Services.GetRequiredService<ILogger<Program>>();
        webHost.Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        });

有人可以指出我在工作示例中的方向还是告诉我我做错了什么?

0 个答案:

没有答案