Understanding Further About InProcess and OutOfProcess ASP.NET Core

An ASP.NET Core web application must be deployed on a server after development is complete in order for end users to use it. ASP.NET Core provides two hosting models, InProcess and OutOfProcess, for deployment to IIS. You can read more about these hosting models and their configuration in this article.

The ASP.NET Core Module is responsible for handling different requests to your web application when it is deployed to IIS. The hosting model for your application is InProcess by default. This indicates that the IIS HTTP Server (IISHttpServer) receives requests from the ASP.NET Core Module. One server that operates in-process alongside IIS is the IIS HTTP Server. Great performance is achieved in comparison to the Out of Process model. In-process models get around ASP.NET Core’s built-in Kestrel web server.

You will not use the IIS HTTP Server if you choose to use the Out-Of-Process hosting model. Instead, your requests are processed by the Kestrel web server. Thus, the Kestrel web server receives your requests through the ASP.NET Core Module. Compared to the in-process model, this communication is slower because it is out-of-process communication.

Let’s look at how to configure the in-process and out-of-process hosting models now that you have a basic understanding of them.

To comprehend the hosting models covered in this article, you must first use Visual Studio to create an ASP.NET Core web application. So feel free to use any of the web application project templates as a model for your work. Use ASP.NET Core version 2.2 or higher, please.

Once you create the project, click on the Build > Publish menu and Web Deploy the output (or manually copy to IIS) to IIS. Once you finish deploying the application locate the web.config file generated during the deployment process. In this web.config you will find a section like this:

<system.webServer>
  <handlers>
    <add name="aspNetCore" path="*" verb="*" 
modules="AspNetCoreModuleV2" />
  </handlers>
  <aspNetCore processPath="dotnet" 
              arguments=".\MyWebApp.dll"	
              stdoutLogEnabled="false" 
              stdoutLogFile=".\logs\stdout"
              hostingModel="inprocess" />
</system.webServer>

As you can see, the hostingModel attribute of the tag is by default set to inprocess.

Now, with this default setting enabled, launch the application from the browser and look at the HTTP headers. One example of an application sample run is shown in the following figure.

The server is Microsoft IIS, as you can see.

The hostingModel attribute should now be changed from inprocess to outofprocess. Launch the software once more. You will receive the following result this time:

As you can see, the Out-Of-Process model is in effect because the server is now Kestrel.

In the preceding example you change the hosting model in the web.config generated during the publish operation. You can also specify the hosting model in project’s .csproj file. Consider the following markup from .csproj file that does that.

<PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>

The hosting model is set to InProcess by the element. You must configure it as follows in order to set it to Out-Of-Process:

 <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>

Use these settings to run the application and verify that the same result is obtained as before.

Happy Coding!

Related Posts

Leave a Reply

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