Header add

In this article we will discuss ASP.NET Core OutOfProcess Hosting Model. If you miss the previous article please follow the link ASP.Net Core Hosting model and Kestrel Web Server in ASP.NET Core. We discuss the below point in details.
  • How to Configure OutOfProcess Hosting in ASP.NET Core ?
  • What is ASP.NET OutOfProcess Hosting ?
  • How does the OutOfProcess Hosting works in ASP.NET Core ?
  • Can we run an asp.net core application without using the built-in kestrel web server ?
  • If Kestrel can be used by itself as a web server which can directly handle and process the incoming HTTP Request, then why do we need a reverse proxy server ?


How to Configure the OutofProcess Hosting in ASP.NET Core Application ?

We can configure the Out Of Process Hosting in two ways in ASP.NET Core.

1st way:

You just need to add the <AspNetCoreHostingModel> element to the applications project file with a value of OutOfProcess as shown below.

2nd way:

The default hosting in ASP.NET Core is OutOfProcess Hosting. That means if you remove the <AspNetCoreHostingModel> element from the application’s project file, then by default OutOfProcess hosting will be used.

What is Out of Process Hosting in ASP.NET Core ?

In the case of the ASP.NET Core OutOfProcess Hosting Model, there are two web servers.
  • An internal webserver which is the Kestrel web Server
  • And an external web server which can be IIS, Apache, and Nginx.
The most important point that you need to keep in mind is depending on how you are running your application with the OutOfProcess hosting model, the external web server may or may not be used.

As we already discussed that the Kestrel web server is a cross-platform web server that is already embedded with your ASP.NET Core application. So if you are using the Out of Process Hosting model for your asp.net core application, then the Kestrel web server can be used in one of the following ways.

1st way:

We can use the Kestrel Web Server as the internet-facing web server which will directly process the incoming HTTP requests. In this scenario, only the Kestrel Server is used and the other one i.e. external web server is not going to be used. So when we run the application using the .NET core CLI then Kestrel is the only web server that is going to be used to handle and process the incoming HTTP request. For more details please check the link Kestrel Web Server in ASP.NET Core

2nd way:

The Kestrel Web Server can also be used with the combination of a reverse proxy server such as IIS, Apache or Nginx. Now obvious question in mind is If Kestrel can be used by itself as a web server which can directly handle and process the incoming HTTP Request, then why do we need a reverse proxy server?

This is because the reverse proxy server provides an additional layer of configuration and security which is not available with the Kestrel Server. It also maintains the load balancing. So it is a good choice to use Kestrel Server along with a reverse proxy server.

So when we use Kestrel Server along with a reverse proxy server, then the reverse proxy server will receive the incoming HTTP requests from the client and then forwards that request to the Kestrel server for processing. Once the Kestrel Server process that request, then it sends the response back to the reverse proxy server which then sends the response back to the requested client over the internet as shown in the below image.
When we run the application directly from Visual Studio, then by default Visual Studio uses IIS Express. Now change the AspNetCoreHostingModel element value as shown below in the application’s project file.

<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>

As we have configured Out of Process hosting model, now the IIS Express acts as a reverse proxy server and Kestrel acts as the internal webserver.

Now, the IIS Express receives the incoming HTTP request and then forwards it to the Kestrel Web Server for processing. The Kestrel Web Server processes the request and sends the response back to the IIS Express which in turn sends the response back to the client i.e. to the browser.

Now run the application, and you will see the worker process as dotnet. So when you are using Out of Process Hosting model, then the Kestrel Web Server is going to hosts the application and process the request irrespective of whether you are using a reverse proxy server or not.

One more thing that you need to keep in mind is, when you are running your application using the .NET Core CLI, then by default, it ignores the hosting setting that you specified in the application’s project file i.e. csproj file. So, in that case, the value of AspNetCoreHostingModel element is going to be ignored.

The .NET Core CLI always uses OutOfProcess Hosting Model and Kestrel is the web server that will host the ASP.NET Core application and also handles the HTTP requests.

Can we run an asp.net core application without using the built-in kestrel web server ?

YES. When we use the InProcess Hosting model, then the application is hosted inside the IIS worker process i.e. w3wp.exe in the case of IIS and iisexpress.exe in the case of IIS Express. That means the Kestrel Web Server is not used with the InProcess hosting model.



  Summary
   In this tutorial we discussed ASP.NET Core Out Of Process Hosting. If have any question related to this topic then give your feedback.


You May Also Like...

Post a Comment

Previous Post Next Post