# Where Is the Request Handling Logic Implemented in ASP.NET Core?

> Discover where ASP.NET Core implements request handling logic. Explore the Kestrel server, HttpApplication bridge, and middleware pipeline for efficient request processing.

- Repository: [.NET Platform/aspnetcore](https://github.com/dotnet/aspnetcore)
- Tags: internals
- Published: 2026-07-13

---

**ASP.NET Core processes incoming HTTP requests through three tightly-coupled layers: the Kestrel server manages socket communication and HTTP parsing, the HttpApplication bridge adapts the server context to the application pipeline, and the middleware pipeline executes the composed RequestDelegate.**

Understanding the request handling logic in ASP.NET Core requires tracing the path from raw TCP packets to controller actions. According to the dotnet/aspnetcore source code, the framework implements a layered architecture that separates network concerns from application logic. This article explores the concrete implementation files and method signatures that define how HTTP requests are processed.

## The Three-Layer Architecture of ASP.NET Core Request Handling

The request handling logic is distributed across three distinct layers, each with specific responsibilities and source files.

### Layer 1: The Server (Kestrel)

**Kestrel** acts as the edge server that implements the generic `IHttpApplication<TContext>` contract. In [`src/Servers/Kestrel/Core/src/KestrelServer.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/KestrelServer.cs), the server reads raw bytes from the network socket and parses HTTP protocols. The parsing logic resides in [`src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs), which handles HTTP/1.x, HTTP/2, and HTTP/3, populating a feature collection that feeds into the `HttpContext`.

### Layer 2: The Host-Application Bridge

The **HttpApplication** class in [`src/Hosting/GenericHost/src/HttpApplication.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/GenericHost/src/HttpApplication.cs) implements `IHttpApplication<HttpContext>`. This class serves as the adapter between the server and the application pipeline. Its `ProcessRequestAsync` method receives the `HttpContext` from Kestrel and forwards it to the user-configured middleware pipeline by invoking the compiled `RequestDelegate`.

### Layer 3: The Middleware Pipeline

The pipeline itself is a compiled **RequestDelegate**. During startup, [`ApplicationBuilder.cs`](https://github.com/dotnet/aspnetcore/blob/main/ApplicationBuilder.cs) in [`src/Hosting/Abstractions/src/ApplicationBuilder.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/Abstractions/src/ApplicationBuilder.cs) chains middleware components together. The [`RequestDelegateFactory.cs`](https://github.com/dotnet/aspnetcore/blob/main/RequestDelegateFactory.cs) file in `src/Http/Http.Extensions/src/` generates the final delegate that executes when the application processes a request, dispatching eventually to endpoints like controller actions or Razor pages.

## How the Request Flow Works in ASP.NET Core

The request handling flow moves from network to application code through specific method calls. First, Kestrel creates the context using the internal `HttpContextFactory`. Then it invokes `IHttpApplication<HttpContext>.ProcessRequestAsync`. Finally, the `HttpApplication` instance dispatches to the `RequestDelegate` built from `IApplicationBuilder`.

```csharp
// 1. Kestrel receives data → creates HttpContext
var httpContext = httpContextFactory.Create(contextFeatures);

// 2. Kestrel calls the HttpApplication implementation
await httpApplication.ProcessRequestAsync(httpContext);

// 3. HttpApplication invokes the compiled middleware pipeline
await _app(context);   // _app is the RequestDelegate built from IApplicationBuilder

```

This sequence mirrors the actual implementation where [`KestrelServer.cs`](https://github.com/dotnet/aspnetcore/blob/main/KestrelServer.cs) handles socket operations, [`HttpApplication.cs`](https://github.com/dotnet/aspnetcore/blob/main/HttpApplication.cs) provides the bridge, and the `RequestDelegate` represents the compiled middleware chain.

## Key Source Files for Request Handling

The following files form the backbone of the ASP.NET Core request handling mechanism:

- **[`src/Servers/Kestrel/Core/src/KestrelServer.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/KestrelServer.cs)** – Entry point for the Kestrel server; manages socket lifecycle and creates the low-level request context.
- **[`src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs)** – Parses HTTP/1.x, HTTP/2, and HTTP/3 protocols and populates the feature collection.
- **[`src/Hosting/Server.Abstractions/src/IHttpApplication.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/Server.Abstractions/src/IHttpApplication.cs)** – Contract that defines the interface between the server and the host.
- **[`src/Hosting/GenericHost/src/HttpApplication.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/GenericHost/src/HttpApplication.cs)** – Concrete `IHttpApplication<HttpContext>` implementation that forwards requests to the middleware pipeline.
- **[`src/Hosting/Abstractions/src/ApplicationBuilder.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/Abstractions/src/ApplicationBuilder.cs)** – Builds the `RequestDelegate` from the configured middleware chain.
- **[`src/Http/Http.Extensions/src/RequestDelegateFactory.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Http/Http.Extensions/src/RequestDelegateFactory.cs)** – Low-level factory that creates the delegate used by the pipeline.

## Summary

- **Kestrel** handles raw network I/O and HTTP parsing in [`KestrelServer.cs`](https://github.com/dotnet/aspnetcore/blob/main/KestrelServer.cs) and [`HttpProtocol.cs`](https://github.com/dotnet/aspnetcore/blob/main/HttpProtocol.cs).
- **HttpApplication** acts as the bridge between the server and middleware pipeline in [`HttpApplication.cs`](https://github.com/dotnet/aspnetcore/blob/main/HttpApplication.cs).
- **RequestDelegateFactory** and **ApplicationBuilder** compile the middleware chain into an executable `RequestDelegate`.
- The `ProcessRequestAsync` method in `HttpApplication` is the critical handoff point from server code to application code.

## Frequently Asked Questions

### What is the role of IHttpApplication in ASP.NET Core?

`IHttpApplication<TContext>` defines the contract that servers like Kestrel use to invoke application logic. The `HttpApplication` class implements this interface in [`src/Hosting/GenericHost/src/HttpApplication.cs`](https://github.com/dotnet/aspnetcore/blob/main/src/Hosting/GenericHost/src/HttpApplication.cs) to bridge the server-created `HttpContext` with the middleware pipeline, specifically through its `ProcessRequestAsync` method.

### How does Kestrel parse incoming HTTP requests?

Kestrel delegates protocol parsing to classes in `src/Servers/Kestrel/Core/src/Internal/Http/`. The [`HttpProtocol.cs`](https://github.com/dotnet/aspnetcore/blob/main/HttpProtocol.cs) file handles HTTP/1.x, HTTP/2, and HTTP/3 parsing, populating a feature collection that becomes the foundation for the `HttpContext` exposed to application code.

### Where is the middleware pipeline built and executed?

The pipeline is constructed during host startup by [`ApplicationBuilder.cs`](https://github.com/dotnet/aspnetcore/blob/main/ApplicationBuilder.cs) in `src/Hosting/Abstractions/src/`. It is compiled into a `RequestDelegate` by [`RequestDelegateFactory.cs`](https://github.com/dotnet/aspnetcore/blob/main/RequestDelegateFactory.cs). Execution occurs when `HttpApplication.ProcessRequestAsync` invokes this delegate, passing the `HttpContext` through each middleware component in sequence.

### What is the difference between HttpApplication and RequestDelegate?

`HttpApplication` is the adapter class that implements `IHttpApplication<HttpContext>` and receives the initial call from the server. A `RequestDelegate` is a compiled function representing the entire middleware chain that `HttpApplication` invokes to process the request through the configured pipeline.