In this tutorial, let us look at the Kestrel Web Server for ASP.NET Core. The way we host our application in ASP.NET Core has gone through some drastic change compared to the previous version of ASP.NET. The Kestrel is the new way to Host to ASP.NET Core Application. It runs within the Application process making it completely self-contained.
In this article
What is Kestrel
The Kestrel is open-source, cross-platform, event-driven, asynchronous I/O based HTTP server. It is developed to host ASP.NET Core applications on any platform. It is included by default in the ASP.NET Core applications.
It is based on libuv
Kestel is an Open source library and is available at GitHub
The older ASP.NET applications are tightly coupled to the Internet Information Services or IIS.
The IIS is a complete web server with all the features that you require out of a Web Server. Over the period it has grown into to a matured web server and along the way, it has added a lot of weight and bloat. It has become one of the best Web servers around and at the same time, it is one of the slowest.
ASP.NET being tightly coupled with IIS carried the burden of the IIS
The newly designed ASP.NET Core applications are now completely decoupled from the IIS. This decoupling makes ASP.NET Core run on any platform making it truly cross-platform
But, it still needs to have the ability to listen to HTTP Requests and send the Response back to the Client. That is where Kestrel comes in
The Kestrel runs in in-process in the ASP.NET Core Applications. Hence, It runs independently of the environment in which it lives.The kestrel Web server is available in the namespace Microsoft.AspNetCore.Server.Kestrel
We looked at program and startup class in the tutorial Application startup in ASP.Core
The Program class contains a static void Main function, which is the entry point to our Application.
public class Program
public static void Main(string args)
public static IWebHost BuildWebHost(string args) =>
The Main method invokes CreateDefaultBuilder, which is responsible to create the web application host.
The CreateDefaultBuilder is a helper method ( click here for the source code)
It calls the UseKestrel method to registers the Kestrel as the server that will be used to host our application
There are two ways you can use the Kestel
- By Itself (Self Hosting)
- Behind another Web server
Under Sef Hosting model the ASP.NET Core applications directly listen to the HTTP Requests from the internet as shown in the image below.
Behind another Web server
Kestrel is not a fully-featured web server. But that is what makes it fast.
It is not advisable to run Kestrel as a standalone web server in the Production environment. It is recommended to run it behind a Fully Featured Web server like IIS, Nginx, apache etc. In such scenario, the Web server acts as a reverse proxy server
The reverse proxy server takes the HTTP request from the internet and passes it to the kestrel server just the way it is received.
The IIS can take the HTTP request and perform some useful processing like logging, request filtering, URL rewrites before passing the request to kestrel.
The following diagram shows the how it is implemented
There are many reasons why you should use this model in the production
- It can limit your exposed surface area. It provides an optional additional layer of configuration and defence.
- Simplifies Load Balancing
- SSL Setup
Only your reverse proxy server requires an SSL certificate, and that server can communicate with your application servers on the internal network using plain HTTP.
- Sharing Single IP with Multiple addresses
- Request FIltering, logging & URL Rewrites etc.
- It can make sure that the application restarts if it is crashes
The CreateDefaultBuilder method calls the UseIISIntegration, which tells ASP.NET that the application will be using the IIS as a reverse proxy in front of Kestrel
Alternatives to Kestrel
The Kestrel is not the only way to host ASP.NET Core applications. There is another web server implementation available in Windows known as HTTP.SYS
Here is the nice tutorial on How to use HTTP sys.
In this tutorial, we learned about the Kestrel Web server. Which is an In-Process web server built to run ASP.NET Core applications on any Platform.