📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š Interview question

What are the hosting models for ASP.NET Core? Compare Kestrel on its own, IIS in-process and out-of-process through the ASP.NET Core Module, and HTTP.sys, and tell me when you would choose each.

ASP.NET Core hosting models: Kestrel as an edge server, Kestrel behind a reverse proxy, IIS in-process and out-of-process via the ASP.NET Core Module (ANCM), and HTTP.sys, with when to choose each.

Junior Theory Intermediate ancm aspnet-core hosting http-sys iis kestrel

🎯 Key points

  • Kestrel is the default cross-platform server and is supported as an edge server in .NET 10: HTTPS endpoints and certificates via Kestrel:Endpoints, limits via KestrelServerLimits
  • IIS hosting uses the ASP.NET Core Module (ANCM V2) configured in web.config
  • In-process (the default) runs the app inside w3wp.exe using IISHttpServer, not Kestrel, and is the faster IIS model
  • Out-of-process runs Kestrel in a separate dotnet process with IIS as a reverse proxy over localhost; useful only when you need Kestrel-specific features or process isolation from w3wp
  • HTTP.sys is a Windows kernel-mode server: Windows auth, port sharing, kernel response caching, no IIS
  • Behind any reverse proxy you need forwarded headers, trusted only from known proxies, so scheme and client IP are correct
  • Security: each in-process app needs its own app pool identity; edge Kestrel needs TLS, limits and no Server header
  • Containers and Linux: Kestrel, usually behind a platform load balancer or ingress

⏱ 30-second answer

Kestrel is the default, cross-platform server built into ASP.NET Core and is fine to run directly, which is what you do in containers and on Linux. On Windows with IIS, the ASP.NET Core Module (ANCM) connects IIS to your app in one of two ways: in-process (the default), where the app runs inside the IIS worker process w3wp.exe using IISHttpServer instead of Kestrel and is fastest on IIS; or out-of-process, where IIS reverse-proxies to Kestrel running in a separate dotnet process. HTTP.sys is a Windows-only, kernel-mode server for when you need Windows authentication, port sharing or kernel caching without IIS. The trade-off: Kestrel is portable and simple, IIS gives Windows process management, and HTTP.sys gives Windows features without IIS.

πŸ—£ Full answer (senior)

How I would answer this in an interview

"There are really three servers. Kestrel is the default: cross-platform, fast, and since ASP.NET Core 2.x it's supported as an edge server facing the internet. In containers on AKS or Azure Container Apps I run Kestrel and let the platform's load balancer or ingress sit in front.

On Windows with IIS, the ASP.NET Core Module in web.config decides how IIS talks to the app. In-process, the default since .NET Core 3.0, loads the .NET runtime into w3wp.exe and uses IISHttpServer, so there's no Kestrel and no loopback hop, which is noticeably faster. Out-of-process starts Kestrel in a separate dotnet process and IIS forwards each request over localhost; I'd choose it only for edge cases like needing Kestrel-specific features or isolating a crash-prone app. The third option is HTTP.sys, a Windows kernel driver: it gives Windows Authentication with Kerberos, port sharing with other apps and kernel-mode caching without needing IIS, which suits intranet apps run as Windows services.

The mistake I see is forgetting what changes behind a proxy: if IIS out-of-process, Nginx or a load balancer terminates TLS, the app sees HTTP and the proxy's IP unless you configure forwarded headers. Pick the server for the platform you deploy to, and treat the proxy as part of the app's configuration."


Comparison

Kestrel (edge or behind LB) IIS in-process IIS out-of-process HTTP.sys
OS Windows, Linux, macOS Windows Windows Windows
Server in the app Kestrel IISHttpServer Kestrel HttpSysServer
Process dotnet / your exe w3wp.exe w3wp.exe + dotnet your exe / Windows service
Windows auth Negotiate package (Kerberos/NTLM) Yes (IIS) Yes (IIS forwards token) Yes, native
Port sharing No Yes (IIS bindings) Yes Yes (URL ACLs)
Typical use Containers, App Service on Linux, AKS Existing IIS estates Rare edge cases Intranet services without IIS

When to choose which

  • New services: Kestrel in a container. Simplest, portable, the platform handles TLS and scaling.
  • On-premises Windows with IIS already managed by ops: in-process hosting. You get app pool recycling, IIS logging and certificate management.
  • Windows service that needs Kerberos or shares a port: HTTP.sys.
  • Azure App Service on Windows: in-process under IIS by default; on Linux App Service it is Kestrel behind the platform front end.

Production example

Moving an internal API from out-of-process to in-process IIS hosting typically removes a loopback hop and the double request parsing; teams report noticeably higher throughput for the same hardware (Microsoft's guidance quotes significantly better performance for in-process). When the same API later moved to AKS, IIS disappeared entirely and Kestrel ran behind the ingress controller, with UseForwardedHeaders restoring the real client IP for audit logs.

πŸ” What the interviewer is checking

Checks that the candidate knows where their app actually runs and the performance and security consequences of that choice.

Green flags

  • Knows in-process is the default IIS model and runs inside w3wp.exe.
  • Can explain why out-of-process is slower and when it is still justified.
  • Names HTTP.sys features: Windows auth, port sharing, kernel caching.
  • Mentions forwarded headers, trusted proxies, TLS on edge Kestrel and per-app pool identities.

Red flags

  • Says IIS is required in production.
  • Doesn't know what ANCM or web.config does in ASP.NET Core.
  • Thinks HTTP.sys works on Linux.
  • Trusts forwarded headers from any source.

πŸ“š Learn in depth

1. The IServer abstraction

ASP.NET Core does not care which server it runs on. The host resolves one IServer from DI and calls StartAsync with the application's RequestDelegate. Kestrel (KestrelServer), IIS in-process (IISHttpServer) and HTTP.sys (HttpSysServer) are three implementations. WebApplication.CreateBuilder registers Kestrel and the IIS integration; when the app is launched by ANCM in-process, the IIS server is used.

2. The ASP.NET Core Module (ANCM)

ANCM is a native IIS module installed by the .NET Hosting Bundle. web.config tells it what to do:

<aspNetCore processPath="dotnet" arguments=".\MyApi.dll" hostingModel="inprocess" />
  • In-process: ANCM loads aspnetcorev2_inprocess.dll, starts the CLR inside w3wp.exe and calls your Main. Requests go from the HTTP.sys kernel queue to IIS to your pipeline in the same process.
  • Out-of-process: ANCM starts dotnet MyApi.dll with a random port in ASPNETCORE_PORT, then proxies each request over HTTP to localhost. It also restarts the process if it crashes.
In-process:     Client ─► HTTP.sys ─► IIS (w3wp.exe: ANCM ─► your pipeline)
Out-of-process: Client ─► HTTP.sys ─► IIS (w3wp.exe: ANCM) ──localhost HTTP──► dotnet (Kestrel ─► pipeline)
Kestrel edge:   Client ─► [cloud LB / ingress] ─► Kestrel ─► pipeline

3. Why in-process is faster on IIS

Out-of-process parses each request twice (IIS, then Kestrel), copies the body across a loopback socket and doubles the connection count. In-process avoids all of that. The constraints: one app per app pool, and the app shares w3wp.exe's lifetime (an app pool recycle restarts your app).

4. HTTP.sys

HTTP.sys is the same kernel driver IIS uses. Hosting on it directly (builder.WebHost.UseHttpSys()) gives kernel-mode request queuing, kernel response caching, Windows authentication without extra packages, and URL-prefix based port sharing (registered with netsh http add urlacl). It cannot run on Linux and does not work with ANCM.

5. Reverse proxies and forwarded headers

Any time something terminates the connection before your app (IIS out-of-process, Nginx, YARP, Azure Front Door, an ingress controller), Request.Scheme, Request.Host and Connection.RemoteIpAddress describe the proxy hop. UseForwardedHeaders reads X-Forwarded-For, X-Forwarded-Proto and X-Forwarded-Host, but only trusts them from configured KnownProxies/KnownNetworks (in .NET 10, also KnownIPNetworks). IIS integration configures this for you automatically.

Try it yourself

  1. Publish an app to a local IIS with the Hosting Bundle; switch hostingModel between inprocess and outofprocess and compare Task Manager processes.
  2. Load-test both with bombardier -c 100 -d 30s and compare requests per second.
  3. Run the same app with UseHttpSys() and enable Windows Authentication; log User.Identity.Name.
  4. Put the app behind a local Nginx container and log RemoteIpAddress with and without UseForwardedHeaders.

πŸ’» Code

Choosing the server in Program.cs. Kestrel is the default; HTTP.sys is opt-in and Windows-only.

// Program.cs
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.AspNetCore.Server.HttpSys;

var builder = WebApplication.CreateBuilder(args);

if (OperatingSystem.IsWindows() && builder.Configuration.GetValue<bool>("Hosting:UseHttpSys"))
{
    // Kernel-mode server: Windows auth and port sharing without IIS
    builder.WebHost.UseHttpSys(options =>
    {
        options.Authentication.Schemes = AuthenticationSchemes.Negotiate;
        options.Authentication.AllowAnonymous = false;
        options.UrlPrefixes.Add("https://+:443/payroll/");
    });
}
else
{
    // Kestrel (also used when IIS hosts out-of-process)
    builder.WebHost.ConfigureKestrel(k => k.AddServerHeader = false);
}

// Behind a proxy or load balancer: trust forwarded headers from known networks only
builder.Services.Configure<ForwardedHeadersOptions>(o =>
{
    o.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
    o.KnownIPNetworks.Add(System.Net.IPNetwork.Parse("10.0.0.0/8"));
});

var app = builder.Build();
app.UseForwardedHeaders(); // first, so later middleware sees the real scheme and client IP
app.MapGet("/whoami", (HttpContext ctx) => new { ctx.Request.Scheme, Ip = ctx.Connection.RemoteIpAddress?.ToString() });
app.Run();
<!-- web.config for IIS: in-process is the default and the faster model -->
<configuration>
  <system.webServer>
    <handlers><add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /></handlers>
    <aspNetCore processPath="dotnet" arguments=".\Payroll.Api.dll" hostingModel="inprocess" stdoutLogEnabled="false" />
  </system.webServer>
</configuration>

⚠ Common mistakes

  • Mistake: Believing Kestrel must always sit behind IIS or Nginx. Why it is wrong: Kestrel in .NET 10 is supported as an edge server, with HTTPS, HTTP/2, HTTP/3 and request limits configured in Kestrel:Endpoints and KestrelServerLimits. Instead: Add a proxy only for TLS offload, WAF, port sharing or central routing.
  • Mistake: Choosing out-of-process IIS hosting by habit. Why it is wrong: It adds a loopback hop, a second connection per request and double header parsing; chatty APIs with many small requests suffer most. Instead: Use the in-process default unless you need Kestrel-only features or want a crash in the app isolated from w3wp.exe.
  • Mistake: Forgetting forwarded headers behind a proxy. Why it is wrong: The app logs the proxy's IP and builds http:// redirect URLs, causing redirect loops. Instead: Configure UseForwardedHeaders with known proxies or networks, early in the pipeline.
  • Mistake: Trusting X-Forwarded-For from anyone. Why it is wrong: Clients can spoof it to bypass IP-based rules or poison audit logs. Instead: Restrict trust to known proxies or networks.
  • Mistake: Trying to use HTTP.sys on Linux or with IIS. Why it is wrong: It is a Windows kernel driver and is incompatible with ANCM. Instead: Use Kestrel with the Negotiate authentication package for cross-platform Windows auth.
  • Mistake: Hosting several apps under one shared app pool identity. Why it is wrong: In-process allows one app per pool, and a shared identity means one compromised app can read the others' files and secrets. Instead: One app pool and least-privilege identity per app.

πŸ› Senior insight: trade-offs

The choice is mostly decided by the platform, not by preference. On Linux containers there is nothing to choose: Kestrel, with the platform's ingress in front. On Windows, the decision is about who owns operations: if an infrastructure team runs IIS with certificate rotation, logging and app pool policies, in-process hosting fits that model. HTTP.sys is a niche tool for Windows services that need Kerberos or URL sharing.

Option When it fits Cost When not to
Kestrel edge in container Greenfield, AKS, Container Apps You or the platform handle TLS Must share :443 on a Windows host
IIS in-process Managed Windows/IIS estate Windows licensing, app pool recycles restart the app Linux or containers
IIS out-of-process Need Kestrel features under IIS Extra hop and process Default choice
HTTP.sys Intranet Windows service with Kerberos Windows-only, URL ACL setup Internet-facing cloud services

πŸ”— Follow-ups the interviewer may ask

  1. When: Candidate mentions running Kestrel behind IIS, Nginx or a load balancer. Why: Checks the practical consequences of running behind a reverse proxy: client IP, scheme and redirect loops.
    How to answer
    • A forward proxy sits in front of clients (corporate egress proxy): clients send requests through it to the internet. For HTTPS it tunnels with CONNECT. HttpClient picks it up from system settings or HTTP_PROXY/HTTPS_PROXY/NO_PROXY.
    • A reverse proxy sits in front of servers (nginx, Envoy, YARP, App Gateway, ingress): it terminates TLS, routes, load balances, caches and adds headers.

    Behind a reverse proxy, the app sees the proxy's IP and often plain http. The proxy passes the originals in X-Forwarded-For and X-Forwarded-Proto, but ASP.NET Core only applies them via the ForwardedHeaders middleware, and by default only trusts proxies on loopback. So UseHttpsRedirection sees http, redirects to https, the proxy forwards as http again: a loop.

    Fix: UseForwardedHeaders first, configured with the proxy's IPs or network in KnownProxies/known networks. Do not trust all sources, or clients can spoof their IP and scheme.

  2. When: Candidate mentions running the app locally under IIS Express or Kestrel. Why: Checks how local hosting profiles (Kestrel vs IIS Express) are configured during development.
    How to answer

    Properties/launchSettings.json defines launch profiles for local development: how to start the app, which URLs, and which environment variables. Visual Studio, Rider, VS Code with C# Dev Kit and dotnet run all read it, but it is not published. In this file I would flag: secrets are committed (a production connection string and API key), so they must be rotated now and moved to user secrets; the environment is Production, which switches on production behaviour and turns off user secrets, and combined with the production connection string means a developer's F5 talks to the live database; and it binds to 0.0.0.0 over plain HTTP, exposing the app to the network. I would replace it with HTTPS and HTTP profiles on localhost using Development, and add a separate production-like profile only if someone needs to test production behaviour against non-production resources.

↩ Usually asked after

More in ASP.NET Core Fundamentals

Last updated 23 Nov 2026.

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me