Kestrel Web Server in ASP.NET Core Application
In this article, I am going to discuss the Kestrel Web Server in ASP.NET Core Application. Please read our previous article before proceeding to this article where we discussed ASP.NET Core InProcess hosting in detail. In our previous article, we discussed that with the OutOfProcess hosting model, there are 2 web servers i.e. one internal web server and one external web server. The internal web server is called as Kestrel and the external web server can be IIS, Apache or Nginx. As part of this article, we are going to discuss the following two important concepts in detail.
- What is a Kestrel Web Server?
- How to run a .NET Core application using .NET Core CLI?
What is a Kestrel Web Server?
As we already discussed the ASP.NET Core is a cross-platform framework. It means it supports developed and run applications on different types of operating systems such as Windows, Linux, or Mac.
The Kestrel is the cross-platform web server for the ASP.NET Core application. That means this Server supports all the platforms and versions that the ASP.NET Core supports. By default, it is included as the internal web server in the .NET Core application.
The Kestrel Web Server generally used as an edge server i.e. the internet-facing web server which directly processes the incoming HTTP request from the client. In the case of the Kestrel web server, the process name that is used to host and run the ASP.NET Core application is dotnet.exe.
As of now, we are using visual studio to run the ASP.NET Core application. By default, the visual studio uses IIS Express to host and run the ASP.NET Core application. So the process name is IIS Express that we already discussed in our previous article. We can also run the ASP.NET Core application from the command line using the .NET Core CLI. The CLI stands for Command Line Interface.
How to run .NET Core application using .NET Core CLI?
When we run an ASP.NET Core application using the .NET Core CLI, then the .NET Core runtime uses Kestrel as the webserver. The .NET Core CLI (Command Line Interface) is a cross-platform tool that is used for developing ASP.NET core applications on cross-platform such as windows, macs or Linux.
Open command prompt and type “dotnet —” and press enter as shown below.
Once you type the “dotnet —” and click on the enter button then you will find lots of commands as shown below.
Using the CLI (above commands)
- You can create a new project using the new command, you can also build the project using the build command, or you can publish the project using the publish command.
- It is possible to restore the dependencies and tools which are required for a .net core project using the CLI
Running .NET Core application using .NET Core CLI
We can do a variety of things using the .NET Core CLI. So let’s see how to run a .NET Core application using CLI. To do so please follow the below steps
First, open the Windows Command Prompt. To do so, open the run window and then type cmd and click on the enter button which will open the command prompt
Then you need to change the directory to the folder which contains your asp.net core application. My project is present in “C:\Users\Pranaya\source\repos\FirstCoreWebApplication\FirstCoreWebApplication” folder so I type as shown below to change the directory.
Once you change the directory then execute the “dotnet run” command as shown in the below image.
Once you click on the enter button, then the .NET Core CLI builds and runs the application. It also shows the URL and you can use this URL to access the application. Here, in my case, the application is available at http://localhost:5000
Now open the browser and navigate to the http://localhost:5000 URL and It should display the worker process name as dotnet as shown below.
So this proves that, in the case of the Kestrel web server, the process that is used to host and run the application is dotnet.exe.
In the next article, we will discuss the OutOfProcess hosting in the ASP.NET Core application. Here, in this article, I try to explain the Kestrel Web Server in ASP.NET Core application in detail. I hope this article will help you to understand the Kestrel Web Server in ASP.NET Core Application.