Asp.Net Core Kestrel Web server

Asp.Net Core Kestrel web server configuration tutorial for beginners.

Kestrel is open-source, event-driven, asynchronous I/O based web server for hosting ASP.NET applications. it uses async I/O library called libuv primarily was developed for node.js

When we create any Asp.Net Core Projects, the Asp.net Core templates include Kestrel web server by default

Kestrel web server is included in the project as a Nuget package Microsoft.AspNetCore.Server.Kestrel

If you have been developing Asp.net application for some long time, then you may have a question what was the necessity of Kestrel when there was well established web server IIS!

Why Kestrel web server when there is IIS?

First reason is, IIS is limited to windows OS only, but now Asp.net core was designed to be hosted on other platform like LINUX, Mac, so there was a need for a web server that can run on different OS apart from windows.

Kestrel provides much efficient request processing to Asp.Net Core applications, which helps improving the application performance.

Kestrel Web server Characteristic
  • Kestrel is cross-platform, runs in Windows, LINUX and Mac.
  • Kestrel webserver can supports SSL
  • Using Kestrel, we cannot have multiple applications running on same port
  • Kestrel is a very light weight webserver that does not have every advanced features of webservers like IIS
  • But Kestrel is much faster compare to IIS
How to use Kestrel Web server?

We can use Kestrel Webserver just by calling the method UseKestrel() in host builder of Program file.

 public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
        .UseKestrel()
        .UseIISIntegration()
            .UseStartup<startup>()
            .Build();
}

Notice .UseKestrel() method in above static BuildWebHost method, Specify Kestrel server to be used by web host. that's how kestrel server is configured in an Asp.Net Core application.

How to start Asp.Net Core app with Kestrel

In asp.net core application when we press F5 to run the application on local machine, it uses “IISExpress” as web server, if you want to use Kestrel web server to run your application on local machine, you just need to click on drop-arrow icon next to “IISExpress” , then select the application name, see the picture below.

kestrel web server

Now if you click on F5, your Kestrel web server will start, and your web page will open up in default browser.

You will see a black DOS window will open up, the window will display all hosting related information.

If you want to shut down the Kestrel web server, you can either close the window or press "control + C" to shut down.

Run using Dotnet CLI

You also can run the application from command prompt, just to open command window and then run the following command.

dotnet run

Before running the above command make you go to project folder location in your DOS window.

Asp.Net Core C# Examples | Join Asp.Net MVC Course