ASP.NET Core InProcess Hosting

Introduction

In this article, we’ll discuss InProcess Hosting in an ASP.NET Core and along the way, we’ll also discuss what is Kestrel server. Please, read our previous article before proceeding to this article where we learn ASP.NET Core Project Structure.

So, within this program.cs file. we have this main method which is the entry point into this application when this application executes the .NET runtime.

program.cs file in asp.net core

The main method calls this method to create a web host builder and that method calls the create default builder static method of this web host class. Now, this creates a default builder method that sets up the web host. that hosts our application with pre-configured defaults as part of the setting of the web host. this creates a default builder method does several tasks.

the tasks performed by this CreateDefaultBuilder() method it sets of the webserver loads. the host and application configuration information from various configuration sources and configures logging.

So, the various configuration sources available in an ASP.NET Core loading. the host and application configuration information.

the create default builder method does configure and set up the webserver from a hosting endpoint. an asp.net core application can host in out of the process.

Is referring to how IIS is hosting your app (web.config).

InProcess: IIS host the app (w3wp.exe or iisexpress.exe)

OutOfProcess: Kestrel host the app, IIS is a proxy to kestrel.

More details on how to configure and what to keep in mind for each one when using.

Configure InProcess hosting in ASP.NET Core

InProcess has significantly better performance according to Microsoft.

To configure InProcess add web config with:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess">
        <environmentVariables />
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

For OutOfProcess:


<?xml version="1.0" encoding="utf-8"?>
configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess">
        <environmentVariables />
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

We’ll discuss over process hosting to configure in-process hosting for your application. there is one simple setting in your asp.net core project file include this element AspNetCoreHostingModel with a value of in the process.

CreateDefaultBuilder() method calls UseIIS() method and host the app inside of the IIS worker process( iisexpress.exe).

So, the InProcess hosting delivers higher request throughput than OutOfProcess hosting.

Without process hosting there are two web servers involved an internal web server and an external web server. But let’s get out of process hosting in detail in our next article. for now, understand without process hosting there are two web servers internal and external.

The internal web server is kestrel and the external web server can be IIS Nginx or Apache depending on the operating system. you have but, within the process hosting there’s only one web server that is the IIS that hosts the asp.net core application.

So, using in-process hosting we do not have the performance penalty of proxying requests between internal and external web servers.

What is Kestrel?

Let’s understand what is Kestrel, the Kestrel is a cross-platform web server for ASP.NET Core. it supports all platforms in versions that .NET Core supports. it’s included by default as an internal server in asp.net core. The kestrel server can uses by itself as an edge server that is an internet-facing web server. that can process incoming HTTP requests from the client the name of the process in kestrel that hosts and runs our asp.net core application dotnet.exe.

kestrel in asp.net core
kestrel inprocess

Thank you for reading this article, I hope you will understand the ASP.NET Core InProcess Hosting. We’ll get into more details about this when we’ll learn Kestrel Web Server in ASP.NET Core in the next article.

Leave a Reply

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