How Asp.Net Core Hosting Model Used in Web Applications?



Asp.net core has significant enhancement to the hosting model. It was expected in the earlier versions to host the Asp.net Core web applications through proxy web servers such as IIS on Windows, Apache or NGINX. However, new Asp.net core 2.2 allows directly hosting the Asp.net application in Windows within IIS without the external server requirements. Thus, this increase the throughput using simple In-Process hosting mechanism.

Hosting Models in ASP.NET Core

ASP.NET is a technology from Microsoft that allows you to create dynamic pages on the web server side.

Hosting asp.net is fully integrated with Windows based software as well as with the operating system itself. This technology is considered quite safe and reliable, as well as easy to use. It is mainly used for the development of in-app products.

Hosting models in ASP.NET Core are of two types i.e. In-process Hosting and Out-of-process Hosting. Before ASP.Net Core 2.2 there was only one hosting model, which is Out-of-process hosting but due to the performance, In- Process Hosting Model in Asp.net core 2.2 versions are introduced.

Introduction of In-process Hosting Model in Asp.net Core

The previous versions of ASP.NET Core required one to host the application in IIS using an Out-of-Process hosting model that proxies through IIS. Requests that hit IIS or IIS Express are forwarded to the ASP.NET Core web application running within Kestrel Web Server. However, with the new In-process hosting, only one server is used for hosting like IIS, Nginx or Linux. It means that instead of forwarding requests to Kestrel, a new Web Server implementation (IISHttpServer) is hosted directly inside the IIS Application Pool, that will serve the request. With the ASP.NET Core 3.1, In-process hosting model is used as a default model whenever you develop a new application using an existing template.

Apparently, this hosting model has much high throughput and performance enhancement on comparing with the Out-Of-Process hosting model.

Out-of-Process Hosting Model

In Out-of-process hosting models, you can either use the Kestrel server directly as a user request facing server or you can deploy the application into IIS which will act as a proxy server and sends requests to the internal Kestrel server. In this kind of hosting model, you have two options for hosting i.e. Using Kestrel and Proxy Server:

1. Using Kestrel

In this, Kestrel itself acts as edge server which directly server user requests which means that one can only use the Kestrel server for the application.

2. Using a Proxy Server

Due to limitations of the Kestrel server, one cannot use this in all the applications. In such cases, one has to use powerful servers like IIS, Apache or NGINX. So, in this situation, this server acts as a reserve proxy server that will redirects every request to the internal Kestrel sever where the application is running. Here, two servers such as IIS and Kestrel are running.

This hosting model is a default model for all the applications implemented earlier .NET Core 2.2 version. One of the limitations of using this type such as performance slowness.

Final thoughts:

As per the facts, most of the  ASP.Net web development companies   certainly wants to use the In-Process hosting model. Since it consumes less resources and provides good performance. As it doesn’t need an additional process for Kestrel and it also avoids extra communication between the IIS and Kestrel. However, there are cases where one may want to choose Out-Of-Process hosting such as in the case of hosting of the same web application in Windows and in Linux. When talking about hosting the application on other platforms, Kestrel is the primary mechanism used to handle HTTP requests on all platforms.

However, running In-Process on IIS is the best way unless you have a very specific requirement for Kestrel.

Main picture credit: Photo by Farzad Nazifi on Unsplash



Comments (0)

Leave a comment