ASP.NET - ASP.NET Hosting Models
Hosting models describe how an ASP.NET Core application runs and how it connects to a web server. They affect performance, deployment and control. ASP.NET Core supports running behind IIS or running independently using its own server.
In-Process Hosting
In this model, the ASP.NET Core app runs directly inside the IIS worker process called w3wp.exe. Because both IIS and the app share the same process, requests are handled faster and with less memory use. This gives the best performance for Windows deployments.
Out-of-Process Hosting
In this model, the app runs in its own process using Kestrel, and IIS works as a reverse proxy. IIS receives the request and forwards it to the Kestrel server. This gives flexibility because the application runs separately, but it is slightly slower than in-process due to forwarding.
Kestrel as a Standalone Server
Kestrel can run without IIS at all. The app can listen to incoming traffic directly and serve responses. This model is useful on Linux, containers and cloud environments where IIS is not available.
Reverse Proxy Layer
When IIS, Nginx or Apache is used in front of Kestrel, they add benefits such as SSL termination, static file caching and request filtering. The ASP.NET Core app focuses on application logic while the proxy handles network concerns.
Choosing the Right Model
On Windows with IIS, in-process hosting provides the best speed. In cloud or Linux environments, Kestrel runs alone or behind Nginx. The choice depends on operating system, deployment style and whether extra proxy features are required.
Example (Program.cs)
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Running on Kestrel");
app.Run(); // Kestrel starts listening for requests
Notes on deployment
-
Windows + IIS → in-process or out-of-process
-
Linux/cloud + Nginx/Apache → proxy to Kestrel
-
Containers → Kestrel only