5.1 KiB
title | author | description | monikerRange | ms.author | ms.custom | ms.date | uid |
---|---|---|---|---|---|---|---|
Kestrel web server in ASP.NET Core | tdykstra | Learn about Kestrel, the cross-platform web server for ASP.NET Core. | >= aspnetcore-3.1 | riande | mvc | 04/04/2023 | fundamentals/servers/kestrel |
Kestrel web server in ASP.NET Core
By Tom Dykstra, Chris Ross, and Stephen Halter
:::moniker range=">= aspnetcore-8.0"
Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the recommended server for ASP.NET Core, and it's configured by default in ASP.NET Core project templates.
Kestrel's features include:
- Cross-platform: Kestrel is a cross-platform web server that runs on Windows, Linux, and macOS.
- High performance: Kestrel is optimized to handle a large number of concurrent connections efficiently.
- Lightweight: Optimized for running in resource-constrained environments, such as containers and edge devices.
- Security hardened: Kestrel supports HTTPS and is hardened against web server vulnerabilities.
- Wide protocol support: Kestrel supports common web protocols, including:
- HTTP/1.1, HTTP/2 and HTTP/3
- WebSockets
- Integration with ASP.NET Core: Seamless integration with other ASP.NET Core components, such as the middleware pipeline, dependency injection, and configuration system.
- Flexible workloads: Kestrel supports many workloads:
- ASP.NET app frameworks such as Minimal APIs, MVC, Razor pages, SignalR, Blazor, and gRPC.
- Building a reverse proxy with YARP.
- Extensibility: Customize Kestrel through configuration, middleware, and custom transports.
- Performance diagnostics: Kestrel provides built-in performance diagnostics features, such as logging and metrics.
Get started
ASP.NET Core project templates use Kestrel by default when not hosted with IIS. In the following template-generated Program.cs
, the xref:Microsoft.AspNetCore.Builder.WebApplication.CreateBuilder%2A?displayProperty=nameWithType method calls xref:Microsoft.AspNetCore.Hosting.WebHostBuilderKestrelExtensions.UseKestrel%2A internally:
:::code language="csharp" source="~/fundamentals/servers/kestrel/samples/6.x/KestrelSample/Program.cs" id="snippet_CreateBuilder" highlight="1":::
For more information on configuring WebApplication
and WebApplicationBuilder
, see xref:fundamentals/minimal-apis.
Optional client certificates
For information on apps that must protect a subset of the app with a certificate, see Optional client certificates.
Behavior with debugger attached
The following timeouts and rate limits aren't enforced when a debugger is attached to a Kestrel process:
- xref:Microsoft.AspNetCore.Server.Kestrel.KestrelServerLimits.KeepAliveTimeout?displayProperty=nameWithType
- xref:Microsoft.AspNetCore.Server.Kestrel.KestrelServerLimits.RequestHeadersTimeout?displayProperty=nameWithType
- xref:Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerLimits.MinRequestBodyDataRate?displayProperty=nameWithType
- xref:Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerLimits.MinResponseDataRate?displayProperty=nameWithType
- xref:Microsoft.AspNetCore.Server.Kestrel.Core.Features.IConnectionTimeoutFeature
- xref:Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinRequestBodyDataRateFeature
- xref:Microsoft.AspNetCore.Server.Kestrel.Core.Features.IHttpMinResponseDataRateFeature
Additional resources
- xref:fundamentals/servers/kestrel/endpoints
- Source for
WebApplication.CreateBuilder
method call toUseKestrel
- xref:fundamentals/servers/kestrel/options
- xref:fundamentals/servers/kestrel/http2
- xref:fundamentals/servers/kestrel/when-to-use-a-reverse-proxy
- xref:fundamentals/servers/kestrel/host-filtering
- xref:test/troubleshoot
- xref:security/enforcing-ssl
- xref:host-and-deploy/proxy-load-balancer
- RFC 9110: HTTP Semantics (Section 7.2: Host and :authority)
- When using UNIX sockets on Linux, the socket isn't automatically deleted on app shutdown. For more information, see this GitHub issue.
[!NOTE] As of ASP.NET Core 5.0, Kestrel's libuv transport is obsolete. The libuv transport doesn't receive updates to support new OS platforms, such as Windows ARM64, and will be removed in a future release. Remove any calls to the obsolete xref:Microsoft.AspNetCore.Hosting.WebHostBuilderLibuvExtensions.UseLibuv%2A method and use Kestrel's default Socket transport instead.
:::moniker-end