In this article, we’ll discuss the Kestrel web server in the ASP.NET Core application in detail. Before, proceeding to this article see the previous article where we discussed an ASP.NET hosting model in detail. As we already discussed with the outer process hosting model there are two web servers. Please, read our previous article before proceeding to this article where we learn ASP.NET Core InProcess Hosting.
1. Internal webserver
2. External web server
So, the internal web server called Kestrel and it is cross-platform for ASP.NET Core application. which means the Kestrel server supports all the platforms and versions that the asp.net core supports and also it’s an edge server. nothing but, internet-facing web server process the incoming HTTP requests from the client.
when we run an ASP.NET Core application using ASP.NET Core CLI. then the .NET runtime uses casteless and with server and the process used to host and run our web application is dotnet.exe for Kestrel web server. if you are using an outer process hosting model for your ASP.NET code application then the Kestrel web server can uses in one of these two ways.
the first is we can use the Kestrel web server as an internet-facing web server. which will process the incoming HTTP requests in scenario one Kestrel web server uses.
another one is an external web server that is not used so when we run the application using dotnet core CLI. then the Kestrel web server is the only webserver we are going to uses to handle and process the incoming HTTP requests.
Create ASP.NET Core web application
Let create an asp.net core application that displays the worker process and runs via dotnet core CLI to create an asp.net core project.
open visual studio 2017 select > file new project in the new project from the window.
Choose an ASP.NET core web application from the middle pane and provide your project name and select the location where you want to create the project.
Let’s open the startup.cs and see the following code.
This code of the data displays that the worker process name open in the command prompt the application by using dotnet run command.
Then, open the browser window and navigate to this URL you will see the worker process named as dotnet
So, in this case, the kestrel is the only server that will handle and process the incoming HTTP request.
the second way is that the kestrel can uses with a combination of reverse proxy servers such as Apache and Nginx. which provides a more layer of configuration and security that is not available in this crystal server. it also maintains load balancing.
So, it is a good choice to use the crystal along with the reverse proxy server. so when we use the Kestrel server along with the reverse proxy server then the reverse proxy the server will receive. the incoming hosting HTTP request from the client and then forwards that request to the kestrel server for processing. once the kestrel server process that request and since the response back to the reverse proxy server. which then sends the response to the requester client over the Internet.
Let us confirm this when we run our ASP.NET Core application from the visual studio than by default. the visual studio uses IIS Express to now change the asp.net core hosting model to the value of the process.
Now, we have configured OutProcess hosting model now the IIS Express acts as a reverse proxy server and kestrel acts as an internal web. So that IIS Express receives the incoming HTTP requests and then forwards it into the crystal web server.
Thank you for reading this article, I hope you will understand the Kestrel Web Server in ASP.NET Core. We’ll get into more details about this when we’ll learn ASP.NET Core appsettings.json file in the next article.