Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching a asp.net core app using VS2017 creates new Application Pool

Each time when I launch the debugger for an ASP.net core application under local IIS from VS2017, a new Application pool is created.

I wish the application to remain stable under the DefaultAppPool 'Identity', and not create a new one.

Where is this setting to influence this?

I can manually set it to the old value using IIS management console, but it's getting tiresome.

Showing the newly created app pool

like image 908
Vincent Avatar asked Oct 16 '22 17:10

Vincent


1 Answers

What you are experiencing is most likely a side effect of the new InProcess hosting model that was introduced with .NET Core 2.2. Check your .csproj file for this line:

<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>

InProcess hosting allows only one IIS site per application pool. It will generate new app pools on the fly if this condition is not met.

You can return to the old Kestrel hosting by removing the above line or by changing it to:

<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>

The difference between In- and OutOfProcess hosting is also reflected in web.config, so you may have to change it there too if you want to go back. Look for the aspNetCore node in system.webServer:

        <aspNetCore 
            processPath="..." 
            arguments="..." 
            stdoutLogEnabled="false" 
            stdoutLogFile=".\logs\stdout"
            hostingModel="InProcess"
        >

Again, you may remove the hostingModel entry or change its value to "OutOfProcess" :

        <aspNetCore 
            ...
            hostingModel="OutOfProcess"
        >

But wait!

You may actually want to reconsider and adopt the new InProcess model for reasons explained in the following.

New InProcess hosting vs. old Kestrel hosting

Before .NET Core 2.2 all Core web applications on IIS were run using a second web server called Kestrel. Kestrel is lightweight and fast but lacks many functions of a full-blown web server. So IIS was used as a proxy in front of Kestrel to add all higher functionality (like redirects, authentication etc.). As you may imagine, cascading two web servers will reduce overall performance and consumes additional resources.

Since .NET Core 2.2 there is another option: InProcess hosting
If you activate InProcess hosting, IIS uses an in-process server implementation for IIS called IISHttpServer. This implementation as well as the Core app itself run in the same process as the IIS worker process. This reduces the resource footprint and increases performance.
There is one limitation though: Each InProcess hosting site in ISS needs a dedicated application pool. You cannot use the same application pool for multiple sites that are configured for InProcess hosting!
Also remember that this unique app pool requires read and write access to the site's folder or any other folders where the app reads and writes files. Otherwise you will get 503 errors.

Basic InProcess configuration

A typical PropertyGroup entry in .csproj for an InProcess project looks like this:

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

You can easily switch back and forth between new InProcess and old Kestrel hosting by simply changing InProcess to OutOfProcess and vice versa.

More info

For more information on InProcess hosting see: ASP.NET Core Hosting Models
For info on migrating existing Core projects to InProcess hosting see: Adopt the IIS in-process hosting model

like image 72
Jpsy Avatar answered Oct 21 '22 03:10

Jpsy