Understanding what options are available for ASP.net Core hosting and their impact on the web application.

The new ASP.NET core 2.2 was upgraded with some improvements to the hosting model if you were to host it with IIS. In the previous versions you were expected to host the ASP.NET Core applications by using a proxy web server such as IIS on windows or NGINX or Apache. However with the new ASP.NET Core 2.2 you could directly host the ASP.NET Core application in Windows within the IIS or IISExpress without the need for an external server. This improves throughput as the new In-Process hosting mechanism doesn’t require internal HTTP requests hopping or other inter-process communication.

In this post I’ll focus on the new In-Process hosting model since that’s what’s changed and is improved, however I’ll be also evaluating the basics of Out-Of-Process hosting model as well and under where it could be best used.

In-Process Hosting

The earlier versions of ASP.NET Core required you to host the application in IIS using an Out-of-Process hosting model that proxies through IIS. Requests that hit IIS or IISExpress are forwarded to the ASP.NET Core web application running within Kestrel Web Server. However with the new In-Process hosting model this is not the case. Instead of forwarding requests to Kestrel, a new Web Server implementation (IISHttpServer) is hosted directly inside the IIS Application Pool, which then serves the request. This is some ways similar to how classic ASP.NET was used to operate.

This implementation accesses native IIS objects to build up the request data required for creating an HttpContext which is then passed on to the ASP.NET Core middleware pipeline. As with the Out-Of-Process hosting model the application pool that hosts the ASP.NET Core Module does not have to be running .NET since the module hooks into the native code IIS pipeline.

Apparently this has much high throughput and performance improvement when compared to the Out-Of-Process hosting model.

In the In-Process hosting model, the ASP.NET Core application runs in the same process as its IIS Worker Process. IIS worker process is the main thread or process which is how the IIS or the IISExpress works on a Windows based server or a machine. This is the default behavior if the web application is hosted in IIS or IISExpress. So in your visual studio if you chose to debug or develop your application via the IIS or IISExpress the application is hosted and run within this IIS worker process.

However do keep in mind that ASP.NET Core applications that target the .NET framework doesn’t support In-Process hosting yet.

The following diagram depict how an in-process hosting model would operate. As you may notice there three important players in this scenario ( ASP.NET Core Module, IHTTPServer, Application Code)