Tuesday, July 30, 2019

ASP.NET Core Hosting Models with IIS

With the introduction of ASP.NET Core 2.2, ASP.NET team has introduced 2 hosting models when we are hosting the ASP.NET Core application in IIS.

One is In-process and the other is Out-of-process. In-process hosting is made possible with the introduction of aspNetCoreModuleV2 which is a required to host ASP.NET Core applications targeting 2.2 or higher. You will get this once you install .NET Core Runtime & Hosting Bundle which is a prerequisite.

You can configure the hosting model pretty easily through one of the following approaches.

1. Through Project Properties in Visual Studio, Under Debug
Visual Studio
2. From the csproj file
csproj file
If the <AspNetCoreHostingModel> property isn't present in the file, the default value is OutOfProcess.

By doing this when the project is published, the web.config file will contain information on whether to run the application In-Process or Out-of-process.
<aspNetCore processPath="dotnet" arguments=".\HelloWorld.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
So what’s is In-process and Out-of-process hosting.


In process basically means the ASP.NET Core application will get run inside IIS Worker process (w3wp.exe) and hence the naming. So here IS HTTP Server (IISHttpServer) is used instead of Kestrel server.


When on Out-of-process, ASP.NET Core application does not run on IIS Worker process, instead it will be running on Kestrel and all the requests are being forwarded to Kestrel.

So what is preferred and why. In-process is the preferred hosting model in IIS. In-process hosting provides improved performance because requests don’t get proxied over to a separate dotnet process. Microsoft states there is an improved throughput of up to 400% on when In-process hosting model is IIS.

More Information,
Host ASP.NET Core on Windows with IIS

Hope this helps.

Happy Coding.


No comments:

Post a Comment