我不使用 Kestrel 作为 Web 服务器并在代码中启用 IIS 集成,但响应 Header 显示服务器是 Kestrel

I don't use Kestrel as the web server and enable IIS integration in the code but Response Header showing the server is Kestrel

我用的是.net core 2.1,发布到IIS 8.5。我很难理解 .NET 核心托管的概念。

program.cs是

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .Build();
   }

你看没有UseKestrel这个词,但是在响应中header,显示Server是Kestrel。

同样在项目文件中,没有<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>。而且我没有UseIISIntegration.

这样的代码

我的问题总结:

  1. 为什么使用 Kestrel
  2. inprocess还是outofprocess
  3. 哪个文件处理这个特殊情况?我假设它是 AspNetCoreModule,但哪个文件?(w3wp?)

您的问题:

  1. Why it uses Kestrel?
  2. Is it inprocess or outofprocess?
  3. Which file handles this particular case? I assume that it is AspNetCoreModule, but which file?(w3wp?)

答案:

  1. 因为您对 运行 使用了 dotnet run 命令。
  2. 外处理
  3. w3wp.exedotnet.exe
  • 您的托管模式是:

  • 您的托管模式不是:

图片来源和参考文档:https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1#out-of-process-hosting-model

如果比较文档:

v 2.1: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.1

和 2.2 版:https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.2

一开始就可以看出版本之间的差异

在 2.1 中:

Because ASP.NET Core apps run in a process separate from the IIS worker process, the module also handles process management. The module starts the process for the ASP.NET Core app when the first request arrives and restarts the app if it crashes. This is essentially the same behavior as seen with ASP.NET 4.x apps that run in-process in IIS that are managed by the Windows Process Activation Service (WAS).

在 v 2.2 中:

The ASP.NET Core Module is a native IIS module that plugs into the IIS pipeline to either: Host an ASP.NET Core app inside of the IIS worker process (w3wp.exe), called the in-process hosting model. Forward web requests to a backend ASP.NET Core app running the Kestrel server, called the out-of-process hosting model.

In-process 是 v 2.2 的默认值。

我在 v 3.1 in-process 模型上测试了我的设置,它按您预期的那样工作。在本地,它 returns kestrel,在 IIS 上,它 returns IIS 服务器。

你所有的答案都在这两个链接下。