What is Kestral C# Asp.net Core?

Kestrel is a cross-platform web server for ASP.NET Core. It is included by default in ASP.NET Core applications and is supported on all platforms where .NET Core runs.

Kestrel serves as the primary HTTP server for ASP.NET Core applications and can be configured to work either as a standalone edge server or in combination with reverse proxy servers like IIS, Nginx, or Apache.

Key Features

  • Cross-platform: Runs on Windows, macOS, and Linux.

  • Lightweight: Minimal overhead and high performance.

  • HTTP/HTTPS support: Handles both HTTP and HTTPS protocols.

  • Async/await support: Built for modern asynchronous programming patterns.

Hosting Models

Kestrel works with different hosting models depending on your deployment scenario −

Hosting Model Usage Process
Out-of-Process Kestrel as standalone or with reverse proxy dotnet.exe
In-Process IIS hosts the application directly w3wp.exe or iisexpress.exe

Note: Kestrel is not used with the In-Process hosting model, as IIS handles HTTP requests directly in this configuration.

Kestrel Deployment Options Standalone Kestrel Internet ? ? Kestrel Direct HTTP handling dotnet.exe Good for development Reverse Proxy + Kestrel Internet ? ? IIS/Nginx ? ? Kestrel Enhanced security & features dotnet.exe Recommended for production

Using Kestrel in Development

When developing ASP.NET Core applications, Kestrel is the default server. You can run your application using the .NET CLI −

Example: Running with .NET CLI

Create and run a simple ASP.NET Core application −

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;

public class Program {
    public static void Main(string[] args) {
        var builder = WebApplication.CreateBuilder(args);
        var app = builder.Build();
        
        app.MapGet("/", () => "Hello World from Kestrel!");
        
        app.Run();
    }
}

To run this application, use the command prompt −

dotnet run

The output shows Kestrel starting −

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.

Configuring Kestrel

You can configure Kestrel options in your application startup −

Example: Custom Kestrel Configuration

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;

public class Program {
    public static void Main(string[] args) {
        var builder = WebApplication.CreateBuilder(args);
        
        builder.WebHost.ConfigureKestrel(options => {
            options.ListenLocalhost(5000);
            options.ListenLocalhost(5001, listenOptions => {
                listenOptions.UseHttps();
            });
            options.Limits.MaxConcurrentConnections = 100;
            options.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(1);
        });
        
        var app = builder.Build();
        app.MapGet("/", () => "Kestrel configured with custom settings!");
        app.Run();
    }
}

The output shows Kestrel listening on multiple endpoints −

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.

Common Use Cases

  • Development: Default server for local development and testing.

  • Microservices: Lightweight server for containerized applications.

  • Production with reverse proxy: Combined with IIS, Nginx, or Apache for production deployments.

Conclusion

Kestrel is ASP.NET Core's built-in, cross-platform web server that provides high performance and flexibility. It can run standalone for development or behind a reverse proxy for production, making it suitable for various deployment scenarios from development to enterprise-grade applications.

Updated on: 2026-03-17T07:04:36+05:30

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements