Loading

ASP.NET Core

What is ASP.NET Core InProcess Hosting?. The Complete ASP.NET Core Developer Course 2023 [Videos].

In-process hosting runs an ASP.NET Core app in the same process as its IIS worker process. In-process hosting provides improved performance over out-of-process hosting because requests arent proxied over the loopback adapter, a network interface that returns outgoing network traffic back to the same machine.

ASP.NET Core InProcess Hosting Model

In this Video, I am going to discuss the ASP.NET Core InProcess Hosting Model in detail. Please read our previous Video before proceeding to this Video where we discussed the. As part of this Video, we are going to discuss the following pointers in detail.

  1. What are the Tasks performed by CreateDefaultBuilder() method?
  2. What is InProcess hosting in ASP.NET Core?
  3. How to Configure InProcess hosting in ASP.NET Core?
  4. How to host ASP.NET Core Application using InProcess hosting Model?
  5. What happens when we set the Hosting model as InProcess?
  6. How does the InProcess hosting work in ASP.NET Core?
  7. What is IIS Express?
  8. Why InProcess Hosting Gives Better Performance that the OutOfProcess Hosting Model?

We are going to work with the same application that we created in our previous Video. As we already discussed when we create an ASP.NET Core web application, then the ASP.NET Core framework creates the following Program class with the Main method for us.

ASP.NET Core InProcess Hosting Model

When we execute an ASP.NET core application then the .NET Core runtime looks for the Main() method. The Main() method is the entry point for the .net core application to execute.

As you can see from the above image the Main() method of the Program class calls the static CreateHostBuilder() method.  Then the CreateHostBuilder() method calls the static CreateDefaultBuilder()method on the Host class. The CreateDefaultBuilder() method sets the web host which will host our application with default preconfigured configurations.

What are the Tasks performed by CreateDefaultBuilder() method?

As part of setting the web host, the CreateDefaultBuilder() method does several things. Some of them are as follows

  1. Setting up the webserver (will discuss in this Video)
  2. Loading the host and application configuration from various configuration sources (will discuss in our upcoming Videos)
  3. Configuring logging (will discuss in our upcoming Videos)

Let us discuss what exactly the CreateDefaultBuilder() method does to configure and set up the webserver. From a hosting point of view, an ASP.NET core Web application can be hosted in two ways i.e. InProcess hosting or OutOfProcess hosting.

Here in this Video, we are going to discuss the InProcess hosting model and in a later Video, we will discuss the hosting model.

Note: When we create a new ASP.NET Core Web application by using any template, by default the project file is created with InProcess hosting which is used for hosting the application in IIS or IIS Express scenarios.

How to verify this?

In order to verify the same, open the project properties. Right-click on your project and select the properties option from the context menu. Once you open the properties window, then select the Debug and have a look at the value of the Hosting Model drop-down list as shown in the below image. The drop-down list contains three values i.e. Default (InProcess), InProcess, and Out Of Process. In our upcoming Videos, we will discuss the Out Of Process hosting model.

What are the Tasks performed by CreateDefaultBuilder() method?

This Confirm that by default it uses In Process hosting model.

How to Configure InProcess hosting in ASP.NET Core?

To configure the InProcess hosting for ASP.NET Core Web application there is only one simple setting, just add the  element to the application project file with a value of InProcess. To do so, just right-click on your application from the solution explorer and then click on the “Edit Project File” option from the context menu as shown in the below code.

How to Configure InProcess hosting in ASP.NET Core?

Once you open the Application Project file then modify it as shown below. As you can see, here we add  element and set its value to InProcess. The order possible value for this element is OutOfProcess.

What happens when we set the Hosting model as InProcess?

What happens when we set the Hosting model as InProcess?

In case of InProcess hosting (i.e. when the CreateDefaultBuilder() sees the value as InProcess for the AspNetCoreHostingModel element in the project file), behind the scene the CreateDefaultBuilder() method internally calls the UseIIS() method. Then host the application inside the IIS worker process (i.e. w3wp.exe for IIS and iisexpress.exe for IISExpress). 

From the performance point of view, the InProcess hosting model delivers significantly higher request throughput than the OutOfProcess hosting model. Why we will discuss this at the end of this Video.

The process name that will be used to execute the application is w3wp in the case of IISSimilarly, if it is IIS Express then the process name will be iisexpress.

Lets Confirm this:

Now if you will run the application, then you will see the following hello world message in the browser.

ASP.NET Core InProcess Hosting Model

You are getting the above message from the following Startup class

ASP.NET Core InProcess Hosting Model

To display the process name in the browser you need to use the System.Diagnostics.Process.GetCurrentProcess().ProcessName within the Startup as shown below. In our upcoming Video, we will discuss the Startup class in detail. For now, just copy-paste code.

namespace FirstCoreWebApplication
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Worker Process Name : " + System.Diagnostics.Process.GetCurrentProcess().ProcessName);
});
});
}
}
}

Now when we run the application from visual studio, and it should display the message in the browser as shown below.

IIS Express in ASP.NET Core

This is because by default Visual Studio uses IISExpress when we run an application as shown in the below image.

What is IIS Express?

What is IIS Express?

The IIS Express is a lightweight, self-contained version of IIS. It is optimized for web application development. The most important point that you need to remember is we use IIS Express only in development, not on production. In production we generally use IIS. In a later Video, we will discuss how to deploy an ASP.NET Core application on IIS.

Why InProcess Hosting Gives Better Performance that the OutOfProcess Hosting Model?

In the case of OutOfProcess hosting, there are 2 web servers

  1. An internal web server and
  2. One external web server.

The internal web server is called  and the external web server can be IISNginx, or ApacheWith the InProcess hosting model, there is only one web server i.e. IIS. So, in the case of the InProcess hosting model, we do not have the performance penalty for navigating the requests between the internal and external web servers. This is the reason why the InProcess hosting model delivers significantly higher request throughput than the OutOfProcess hosting model.

Why InProcess Hosting Gives Better Performance that the OutOfProcess Hosting Model?


See All

Comments (231 Comments)

Submit Your Comment

See All Posts

Related Posts

ASP.NET Core / Blog

What is ASP.NET Core?

ASP.NET Core is the new version of the ASP.NET web framework mainly targeted to run on .NET Core platform.
27-jan-2022 /16 /231

ASP.NET Core / Blog

What is ASP.NET Core Framework?

ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-enabled, Internet-connected apps. With ASP.NET Core, you can: Build web apps and services, Internet of Things (IoT) apps, and mobile backends. Use your favorite development tools on Windows, macOS, and Linux.
27-jan-2022 /16 /231

ASP.NET Core / Blog

How to Setup ASP.NET Core Environment ?

ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-enabled, Internet-connected apps. With ASP.NET Core, you can: Build web apps and services, Internet of Things (IoT) apps, and mobile backends. Use your favorite development tools on Windows, macOS, and Linux.
27-jan-2022 /16 /231