Multiple ASP.NET Core Web API instances runs only once
I have an ASP.NET Core 8.0 Web API hosted on two IIS applications (app-1 and app-2) under the Default Web Site on a Windows 11.
Both IIS applications point to the same physical path (inetpub\wwwroot\myapp
) and each application has its own dedicated application pool (app1
and app2
). The application pools have unique identities (app1svc
and app2svc
), both of which are members of the Administrators group.
In the Web API, I have an AppEvents
class implementing IHostedService
, with StartAsync
and StopAsync
methods to handle application start and stop events. In the Program.cs
, I register it using builder.Services.AddHostedService<AppEvents>()
.
When accessing http://localhost/app-1
, the StartAsync
method is triggered as expected. However, when accessing http://localhost/app-2
, the StartAsync
method does not execute. It seems that the application starts only once, despite both IIS apps pointing to the same physical directory.
I've tried changing the AspNetHostingModel
from InProcess
to OutOfProcess
, but the behavior remains the same.
Is there a way to deploy multiple instances of the same web app, each running separately but pointing to the same physical directory, so that each instance correctly triggers its own StartAsync
?