.Net Core AspNetCoreHostingModel 是什么意思?

Igo*_*ova 9 .net-core asp.net-core

通过此链接,您可以阅读有关 ASP.NET Core 模块的信息

要将应用程序配置为进程内托管,请将属性添加到应用程序的项目文件中,其值为 InProcess(进程外托管使用 OutOfProcess 设置)

我读了好几遍,但我不明白这是什么意思?

何时必须使用 OutOfProcess,何时必须使用 InProcess?

这些模型的优缺点?

做决定时要依靠什么?

Sil*_*mor 7

指的是 IIS 如何托管您的应用程序 (web.config)。

InProcess:IIS 托管应用程序(w3wp.exe 或 iisexpress.exe)

OutOfProcess:Kestrel 托管应用程序,IIS 是 Kestrel 的代理。

有关如何配置以及使用时要记住的内容的更多详细信息

根据微软的说法,“InProcess”具有明显更好的性能。

要配置InProcess添加 web 配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
        <environmentVariables />
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>
Run Code Online (Sandbox Code Playgroud)

对于进程外

<?xml version="1.0" encoding="utf-8"?>
configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess">
        <environmentVariables />
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>
Run Code Online (Sandbox Code Playgroud)

当您将在 my-api 文件夹中生成构建或使用以下命令直接发布到您的服务器时:

dotnet publish -o my-api -c release
Run Code Online (Sandbox Code Playgroud)

会照顾你的 %LAUNCHER_PATH% 和 %LAUNCHER_ARGS%。

您在最初的问题中所指的可能是关于 .csproj 配置,它规定了应用程序如何在本地运行,默认为OutOfProcess

  • 也许在发布此信息时默认为 OutOfProcess,但现在(至少在 VisualStudio2019 社区中)托管模型显示“默认(进程中)” (2认同)