Lessons in this course (9)

5. Hosting ASP.NET Core on IIS — in-process vs out-of-process

Intermediate★ Must knowLesson 5 of 9

Prerequisite: install the .NET Hosting Bundle (runtime + ASP.NET Core Module V2) on the server, then restart IIS (net stop was /y && net start w3svc).

text
In-process (default, fastest):   HTTP.sys → w3wp.exe [ ANCM → your app via IISHttpServer ]
Out-of-process:                  HTTP.sys → w3wp.exe [ ANCM ] ──HTTP──▶ dotnet.exe/YourApp.exe [ Kestrel ]
xml
<!-- web.config generated by dotnet publish -->
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\Shop.Web.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
                  hostingModel="inprocess">
        <environmentVariables>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

Steps: dotnet publish -c Release -o C:\sites\shop → app pool No Managed Code → site pointing to the publish folder → bindings + certificate → permissions → browse. For self-contained publishes, processPath is .\Shop.Web.exe.

In-processOut-of-process
ServerIIS HTTP server inside w3wpKestrel in a separate process
PerformanceHigher (no extra hop)Lower (loopback proxy)
Apps per poolOne ASP.NET Core app per app poolSeveral possible
Use whenDefaultNeed Kestrel-specific features or multiple apps per pool

Zero-downtime-ish deploys: drop an app_offline.htm file in the site folder (ANCM shuts the app down and serves that page), copy new files, delete the file. Web Deploy can do this automatically (-enableRule:AppOffline).