.NET core web applications can be executed on different web servers. .NET itself comes with Kestrel server. This article talks about what is kestrel server, what are different ways to configure it and how it can be enabled.
What is it ?
Kestrel is cross-platform, HTTP Server implementation. This is by default available in .NET, you do not need to install any additional packages.
Kestrel can be used in any of the two ways mentioned below:
- Kestrel can be configured to directly process the requests from any network, including internet
- OR Kestrel can be configured to work with a reverse proxy server (like IIS, apache, or Nginx).
When Kestrel is configured with a reverse proxy server, the reverse proxy server accepts requests from internet and then forwards those requests to Kestrel.
How to enable it ?
If a new ASP .NET Core web application project is created using Visual studio, the default template code inside CreateHostBuilder method gives call to ConfigureWebHostDefaults, which internally uses UseKestrel method.
|public class Program|
|public static void Main(string args)|
|public static IHostBuilder CreateHostBuilder(string args) =>|
ASP .NET core application, as we all know, can be executed using Visual Studio. Different launch profiles can be defined in
launchsettings.json, and then visual studio can be configured to load one of the profile.
If we use Visual Studio for Mac, the app and server are started by the Mono Soft-Mode Debugger. If we use Visual Studio for Windows, the web app will start with either IIS Express/ASP.NET Core Module or the console.
Visual Studio Code is one of the famous editors now, because it is lightweight and can be used for any type of development work. Visual studio code has a plugin, Omnisharp, which can be used for app development using C#. It also enables debugging the .NET core app. Visual Studio code is available on Windows, Linux and MacOS.
We can also use dotnet CLI to run the applications. If dotnet CLI is used, it uses Kestrel server.
Kestrel server uses different configurations. The configurations can be provided via
environment variables or via
appsettings.json file, or via
As this is introduction post, let’s discuss about very basic setting. When a web app is run, it should listen to some URLs. If no configuration is specified, by default Kestrel listens to two URLs:
In next article, we will have a look at how to change the binding URLs for applications running using Kestrel server.
Have you already been using Kestrel ? Let me know your thoughts.