Learn How .Net Core Hosting Works

by | Aug 16, 2023 | .Net Core, Learn | 0 comments

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.
.net core in-proc 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.
dot net core outprocess hosting

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.
Kestral With Reverse Proxy

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

Submit a Comment

Your email address will not be published. Required fields are marked *

Related Posts

Delegates in C#: Complete tutorial

Learn Delegates c# In C#, a delegate is a type that represents references to methods with a particular parameter list and return type. Delegates provide a way to encapsulate a method, and they are often used for defining callback methods and implementing event...

Inheritance in C# oops complete guide

Inheritance Table of content: Topics1Why i wrote this article2Inheritance - complete guide3All possible scenarios based/ tricky in/out type of Interview questions Why i wrote this article? When I was preparing c#/oops, the main challenge was information was scattered...

Learn Angular Directives

Angular Directives Angular directives are an essential part of the Angular framework, allowing you to extend the HTML vocabulary to build dynamic and interactive web applications. There are three main types of directives in Angular: Components: Components are the most...

.Net Core Garbage Collector

Garbage collection   Garbage collection (GC) in .NET Core is an automatic memory management technique that reclaims unused memory. It simplifies memory management for developers and reduces memory leaks and bugs.   The GC identifies and collects objects that...

Most Useful Git Commands

Git commands you should know: git init: Initializes a new Git repository in the current directory. git clone [repository_url]: Creates a copy of a remote repository on your local machine. git add [file]: Stages changes for commit. You can use git add . to stage all...

.Net Core Introduction

INTRODUCTION .NET Core is a modern, cross-platform, and open-source development platform developed and maintained by Microsoft. It provides developers with a fast, flexible, and modular framework for building applications for Windows, Linux, macOS, iOS, and Android....

Delegates in C#: Complete tutorial

Learn Delegates c# In C#, a delegate is a type that represents references to methods with a particular parameter list and return type. Delegates provide a way to encapsulate a method, and they are often used for defining callback methods and implementing event...

Inheritance in C# oops complete guide

Inheritance Table of content: Topics1Why i wrote this article2Inheritance - complete guide3All possible scenarios based/ tricky in/out type of Interview questions Why i wrote this article? When I was preparing c#/oops, the main challenge was information was scattered...

Learn C# oops Polymorphism

Polymorphism Simplifying Polymorphism in C# with Examples Polymorphism is a fundamental concept in object-oriented programming (OOP), and it can be understood more easily by breaking it down into its key components. What is Polymorphism? At its core, polymorphism...

Learn Angular Directives

Angular Directives Angular directives are an essential part of the Angular framework, allowing you to extend the HTML vocabulary to build dynamic and interactive web applications. There are three main types of directives in Angular: Components: Components are the most...

.Net core Fun FACTS to choose other backend but NOT .Net Core

Funny Excuses to Avoid Learning and Using .NET Core for Your Next Backend Web API (And Why You Should Consider Node.js and Other Popular Alternatives Instead) In the world of backend web development, there are numerous technologies to choose from. One option that...

.Net Core Garbage Collector

Garbage collection   Garbage collection (GC) in .NET Core is an automatic memory management technique that reclaims unused memory. It simplifies memory management for developers and reduces memory leaks and bugs.   The GC identifies and collects objects that...

Most Useful Git Commands

Git commands you should know: git init: Initializes a new Git repository in the current directory. git clone [repository_url]: Creates a copy of a remote repository on your local machine. git add [file]: Stages changes for commit. You can use git add . to stage all...

Commonly used commands for .net Core Good to remember

Most userful commands for .net Core. Good to remember. dotnet new: This command is used to create a new project based on a specified template. It generates the basic structure and files required for a .NET Core application. Example: dotnet new console dotnet clean:...

.Net Core Introduction

INTRODUCTION .NET Core is a modern, cross-platform, and open-source development platform developed and maintained by Microsoft. It provides developers with a fast, flexible, and modular framework for building applications for Windows, Linux, macOS, iOS, and Android....

.Net Framework Basics CLR CTS CTS MSIL

CLR (Common Language Runtime) Responsible for program execution in .Net Framework Some crucial role of CLR- Memory Management: The CLR is responsible for managing memory allocation and deallocation in .NET applications. It includes automatic memory management through...

.Net Core vs .Net Framework differences

CLR vs Core CLR What is CoreCLR The CoreCLR provides many similar functionalities as the CLR, but it is specifically designed for the cross-platform nature of .NET Core. General CLR feature includes features like Just-In-Time (JIT) compilation, garbage collection,...

Understand Middleware in .Net Core

Middleware is a piece of software that handles http request and response. In simple term, .net core works with middleware in order to enhance performance of our application rather than having big chunk of framework component/ libraries at once, for which most of the...