In-process vs Out-of-process in IIS
The common denominator - the ASP.NET Core Module (ANCM)
Regardless of the mode, IIS does not natively host an ASP.NET Core application (as it did with old ASP.NET/System.Web) - it needs an intermediary: the ASP.NET Core Module (ANCM), an IIS plugin that translates HTTP requests between IIS and the .NET application.
Out-of-process - Kestrel as a separate process
Klient → IIS (w3wp.exe, tylko REVERSE PROXY) → ANCM → Kestrel (dotnet.exe, OSOBNY proces) → Twoja aplikacja
<!-- web.config -->
<aspNetCore processPath="dotnet" arguments=".\MyApp.dll" hostingModel="OutOfProcess" />
IIS acts here solely as a reverse proxy - it accepts the request on port 80/443, passes it through an internal channel to a separate dotnet.exe process, in which Kestrel and your application actually run. This was the default model in ASP.NET Core 1.x/2.x.
Consequences:
- An additional process hop (the proxy) on every request - a measurable performance overhead
- The application can run independently of IIS (e.g. testing locally with dotnet run, with no IIS at all) - because Kestrel listens on its own port anyway
- An application crash doesn't crash the IIS process (w3wp.exe) - greater isolation
In-process - Kestrel INSIDE the IIS process
Client → IIS (w3wp.exe, Kestrel RUNS IN THE SAME PROCESS through ANCM) → Your application
<aspNetCore processPath="dotnet" arguments=".\MyApp.dll" hostingModel="InProcess" />
Here ANCM hosts the .NET CLR inside the IIS worker process (w3wp.exe) - there is no separate dotnet.exe process, no proxy between two processes. The request goes directly to your application through IIS's native interface (IIS HTTP Server, not a real Kestrel-over-the-network, just an in-process implementation of the same server contract).
Consequences:
- No proxy hop - measurably faster (Microsoft cites a difference on the order of several dozen percent of throughput in benchmarks)
- This is the default model since .NET Core 2.2+ - if you don't configure it otherwise, you get InProcess
- An application crash crashes the whole IIS worker process (w3wp.exe) - less isolation, IIS has to restart it, which kills all the other applications in the same pool (if they share the worker process)
- It can't be run without IIS (there is no standalone listening Kestrel) - local testing requires a different way of running (dotnet run in effect uses Kestrel out-of-process, regardless of what you set for IIS)
Configuration in a Web API project (.csproj)
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> <!-- albo OutOfProcess -->
</PropertyGroup>
Or directly in the generated web.config (if you publish to IIS through dotnet publish):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<aspNetCore processPath="dotnet"
arguments=".\MyOrderApi.dll"
stdoutLogEnabled="false"
hostingModel="InProcess" />
</system.webServer>
</configuration>
What it looks like from the perspective of the Web API's Program.cs - no difference in code
This is an important, practical detail: the application code is identical regardless of the hosting mode - the difference is purely configuration (the web.config/.csproj file), it doesn't touch Program.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.WebHost.UseIIS(); // NIEJAWNIE dodane przez szablon .NET, gdy publikujesz do IIS
var app = builder.Build();
app.MapControllers();
app.Run();
UseIIS() (or UseIISIntegration() in older versions) registers the appropriate server (IIS HTTP Server for In-process) - but whether that server is used at all depends on the hostingModel setting in the IIS configuration, not on this call.
Comparison table
| In-process | Out-of-process | |
|---|---|---|
| Where the application runs | Inside w3wp.exe |
A separate dotnet.exe process |
| Performance | Higher (no proxy) | Lower (an extra hop) |
| Isolation from IIS | Low (a crash = an IIS worker restart) | High (an app crash ≠ an IIS crash) |
| Default since | .NET Core 2.2+ | .NET Core 1.x/2.0/2.1 |
| Typical use | The standard choice today | Rarely - legacy, or a need for strong process isolation |
A trick question in an interview
"Is InProcess always better?" - Not always. If you host many independent applications in one Application Pool (a rare but possible configuration), OutOfProcess gives better isolation - a crash of one app doesn't take the others with it. In a typical scenario (one app = one pool) InProcess is the right, default choice.
Summary
In-process hosts your ASP.NET Core application (and its server implementation,
IIS HTTP Server) inside the same process as IIS (w3wp.exe) - no proxy, higher performance, but an application crash crashes the whole IIS worker process. Out-of-process keeps the application (with a real Kestrel) in a separatedotnet.exeprocess, and IIS acts as a reverse proxy - an extra network/process hop, but better isolation. Since .NET Core 2.2 In-process is the default, and it is the right choice in most Web API scenarios hosted on IIS.