What is Kestrel in ASP.NET Core?
π‘ Concept Name
Kestrel Web Server
π Quick Intro
Kestrel is the default, cross-platform web server used in ASP.NET Core applications. It handles HTTP requests and serves as the core server layer for hosting .NET apps.
π§ Analogy / Short Story
Think of Kestrel as the engine of a carβit does the heavy lifting behind the scenes. If IIS or Nginx is the fancy exterior, Kestrel is what powers the ride by actually handling the web traffic under the hood.
π§ Technical Explanation
Kestrel is a lightweight, high-performance web server developed by Microsoft. It supports both HTTP/1.x and HTTP/2. It's often used as:
- πΈ Standalone web server (especially during development)
- πΈ Reverse proxy backend when paired with IIS, Nginx, or Apache
Itβs optimized for throughput and low latency. You can configure Kestrel directly in Program.cs
or appsettings.json
.
π― Purpose & Use Case
- β Required for running ASP.NET Core apps
- β Enables cross-platform hosting
- β Can be used as a standalone server
- β Supports HTTPS and socket binding
π» Real Code Example
// Program.cs in ASP.NET Core
var builder = WebApplication.CreateBuilder(args);
// Configure Kestrel
builder.WebHost.ConfigureKestrel(options => {
options.ListenAnyIP(5000); // HTTP
options.ListenAnyIP(5001, listenOptions => listenOptions.UseHttps());
});
var app = builder.Build();
app.MapGet("/", () => "Kestrel is running!");
app.Run();

β Interview Q&A
Q1: What is Kestrel?
A: Itβs the default web server for ASP.NET Core applications.
Q2: Is Kestrel cross-platform?
A: Yes, it runs on Windows, Linux, and macOS.
Q3: Can you use Kestrel in production?
A: Yes, often behind a reverse proxy like IIS or Nginx.
Q4: What protocol versions does Kestrel support?
A: HTTP/1.x and HTTP/2.
Q5: What port does Kestrel use by default?
A: Port 5000 for HTTP, 5001 for HTTPS.
Q6: Can you configure Kestrel in code?
A: Yes, using ConfigureKestrel in Program.cs.
Q7: What is the use of a reverse proxy with Kestrel?
A: To add features like SSL termination, port sharing, and load balancing.
Q8: Why not use Kestrel alone in production?
A: It doesnβt support advanced features like Windows auth or port sharing.
Q9: Does Kestrel support WebSockets?
A: Yes, it fully supports WebSockets and HTTP2.
Q10: How do you test Kestrel locally?
A: Run the app and access localhost:5000 or 5001 in a browser.
π MCQs
Q1. What is Kestrel in ASP.NET Core?
- Logging framework
- Database tool
- The default web server
- ORM tool
Q2. Which protocol does Kestrel support?
- Only HTTP/1
- Only HTTP/2
- HTTP/3 only
- HTTP/1.x and HTTP/2
Q3. Which port is default for Kestrel HTTP?
- 80
- 5001
- 5000
- 443
Q4. Is Kestrel cross-platform?
- No
- Only Windows
- Yes
- Only Linux
Q5. What method is used to configure Kestrel?
- UseKestrel
- AddKestrel
- ConfigureKestrel
- KestrelSetup
Q6. Can Kestrel be used in production?
- No
- Only for local dev
- Yes, often behind a reverse proxy
- Only with IIS
Q7. Why use a reverse proxy with Kestrel?
- To bypass Kestrel
- To handle HTTPS and advanced configs
- To increase memory
- To disable logging
Q8. How to test Kestrel locally?
- Kestrel dashboard
- ASP.NET Studio
- Use localhost:5000
- System tray icon
Q9. Can Kestrel host static files?
- No
- Only in IIS
- Yes, with UseStaticFiles middleware
- Only in Razor Pages
Q10. Which JSON file can configure Kestrel endpoints?
- launchSettings.json
- web.config
- env.json
- appsettings.json
π‘ Bonus Insight
Kestrel uses the libuv
library internally on older versions but now uses managed sockets for better performance. It's been benchmarked to be one of the fastest web servers available.
π PDF Download
Need a handy summary for your notes? Download this topic as a PDF!