Hosting In .NET Core
In ASP.NET Core, there are two hosting models available: in-process hosting and out-of-process hosting.
In-process Hosting (Default):
- In the in-process hosting model, a single web server (e.g., IIS) is used directly to host the application.
- To enable in-process hosting, include “AspNetCoreHostingModel” in the project file.
- The hosting configuration can be done using the “CreateDefaultBuilder” method.
- By calling the “UseIIS()” method, the application is hosted inside the IIS worker process (W3wp.exe or iisexpress.exe in the development environment).
- In-process hosting delivers higher request throughput compared to out-of-process hosting.
Out-of-process Hosting:
- Out-of-process hosting involves two web servers: an internal web server (Kestrel) and an external web server (IIS, Apache, or NGINX).
- Kestrel is a cross-platform web server for .NET Core, included by default in ASP.NET Core.It can be used as an edge server, directly processing incoming HTTP requests from clients.
- The external web server acts as a reverse proxy server, forwarding requests to the Kestrel internal server and handling the response.
- Out-of-process hosting is useful when additional configuration, security, or integration with existing infrastructure is required.
Whate are worker process?
Worker processes are separate instances of an application that handle incoming requests, execute application code, and serve responses back to clients in web hosting environments.
Dotnet.exe:
- The process that hosts and runs ASP.NET Core applications in Kestrel is called “dotnet.exe”.
- It is used when running the application with the CLI (Command-Line Interface) for .NET Core.
- The CLI is a cross-platform tool for developing .NET applications and supports commands such as “dotnet new”, “dotnet build”, “dotnet run”, and more.
IIS Worker Process:
- In the in-process hosting model within IIS, the IIS worker process, known as w3wp.exe (or iisexpress.exe in the development environment), takes care of handling incoming requests and serving the ASP.NET Core application.
Kestrel Modes:
Internet-facing web server:
- In this mode, the application uses the dotnet.exe process to run and host the .NET Core application without the need for an external web server.
- This mode is suitable for directly facing the internet.
Combination with a reverse proxy server:
- In this mode, Kestrel is not directly facing the internet but is behind a reverse proxy server such as IIS, NGINX, or Apache.
- The reverse proxy server forwards incoming requests from the internet to the Kestrel internal server and handles the response.
- This mode is useful when additional configuration, security, load balancing, or integration with existing infrastructure is required.
Which type of Dot Net Core hosting I should use and when?
Out-of-process hosting:
- Use out-of-process hosting (Kestrel + external web server) when additional configuration, security, or integration with existing infrastructure (such as load balancing) is required.
This combination allows for flexibility and scalability in handling incoming requests.
Single Kestrel (in-process hosting):
Use single Kestrel (in-process hosting) when simplicity and high performance are the primary concerns.
This approach eliminates the need for an external web server and allows the application to directly process incoming requests.
Combination with a reverse proxy server:
Use a combination of Kestrel with a reverse proxy server (such as IIS, NGINX, or Apache) when additional layer of configuration, security, or advanced features provided by the reverse proxy are needed.
This configuration is suitable for scenarios where the reverse proxy can handle tasks such as load balancing, SSL termination, caching, and request routing.
In-process hosting (Default):
- The default in-process hosting model is suitable for most applications, providing a straightforward setup and high request throughput.
It uses a single web server (such as IIS) to directly host the application without the need for an external web server.
Hope you enjoy learning through my article. In case you found any missing information or your suggestion to make this article better, kindly leave a comment below. Please subscribe newsletter so i can publish more content!
0 Comments