Host your ASP.NET Core 2.2 Web App with IIS in and out of process hosting models

One of the new features of ASP.NET Core 2.2 is support for hosting ASP.NET Core Web App with IIS using in-process or out-of-process hosting model.

Category Fundamentals | Tags:

Published: 26 June 2019

One of the new features of ASP.NET Core 2.2 is support for hosting ASP.NET Core Web App with IIS using in-process or out-of-process hosting model. This article will cover steps needed to

  • Host ASP.NET Core 2.2 Web API with IIS using in-process hosting model
  • Host ASP.NET Core 2.2 Web API with IIS using out-of-process hosting model
  • Host ASP.NET Core 2.2 Web API in Docker Windows containers (with IIS)

In ASP.NET Core 2.2, a new ASP.NET Core Module (AspNetCoreModuleV2) has been introduced which is a native IIS module that plugs into the IIS pipeline and provides in-process or out-of-process hosting capabilities. AspNetCoreModule used to be the module in previous version.


The dev tools used to develop these components are Visual Studio 2017.


ASP.NET Core 2.2 in-process hosting model with IIS

The main pointers about in-process hosting model with IIS are

  • This is the default hosting model on creating a new ASP.NET Core 2.2 app where ASP.NET Core app is hosted within IIS worker process (w3wp.exe).
  • When hosting in-process, ASP.NET Core module uses an in-process server implementation for IIS, called IIS HTTP Server (IISHttpServer) and avoids the additional cost of reverse-proxying requests over to a separate dotnet process.
  • You can specify in-process hosting model by
    • Editing project file i.e. <AspNetCoreHostingModel> InProcess </AspNetCoreHostingModel>
    • Navigate to Project Properties > Debug > Web Server Settings and choose Hosting Model (you need to select IIS Express profile)
  •  You need to use one app pool per app as sharing an app pool among apps isn’t supported.
  • The new module is only capable of hosting .NET Core in the IIS process.

A sample web.config on publishing ASP.NET Core 2.2 Web App using in-process hosting model is displayed below

<?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="dotnet" arguments=".\SampleWebAppForIIS.dll"
                    stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
                    hostingModel="InProcess" />
        </system.webServer>
    </location>
</configuration>


ASP.NET Core 2.2 out-of-process hosting model with IIS

The main pointers about out-of-process hosting model with IIS are

  • Kestrel Server is used instead of IISHttpServer. The ASP.NET Core module forwards requests to ASP.NET Core app running Kestrel Server.
  • When hosting out-of-process, the module only works with Kestrel. The module is incompatible with HTTP.sys.
  • You can specify out-of-process hosting model by
    • Editing project file i.e. <AspNetCoreHostingModel>OutOfProcess </AspNetCoreHostingModel>
    • Navigate to Project Properties > Debug > Web Server Settings and choose Hosting Model (you need to select IIS Express profile)
    • In case you do not specify AspNetCoreHostingModel in project file, it defaults to out-of-process hosting model.

A sample web.config on publishing ASP.NET Core 2.2 Web App using out-of-process hosting model is displayed below

<?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="dotnet" arguments=".\SampleWebAppForIIS.dll"
                    stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
                    hostingModel="OutOfProcess" />
        </system.webServer>
    </location>
</configuration>