admin管理员组

文章数量:1334397

I've an asp core 8.0 webapi published on two IIS app (the OS is Windows 11), named app-1 and app-2, under default web site, pointing the same physycal path (inetpub\wwwroot\myapp). Each IIS app has an application pool, named app1 and app2. Each application pool has an identity, named app1svc and app2svc member of administrators group. In the webapi app I've an AppEvents class, inherited from IHostedService, with a StartAsync and StopAsync function to intercept the starting and stopping application events (in the program.cs I've "builder.Services.AddHostedService()" code line). Opening in the browser the http://localhost/app-1 the StartAsync executes, but opening the http://localhost/app-2 the StartAsync doeasn't execute. That is, the (physical) app starts only once.

Changing the AspNetHostingModel from InProcess to OutOfProcess the result is the same. Is there a way to publish multiple instances of webapp pointing the same physycal app executing each separately?

I've an asp core 8.0 webapi published on two IIS app (the OS is Windows 11), named app-1 and app-2, under default web site, pointing the same physycal path (inetpub\wwwroot\myapp). Each IIS app has an application pool, named app1 and app2. Each application pool has an identity, named app1svc and app2svc member of administrators group. In the webapi app I've an AppEvents class, inherited from IHostedService, with a StartAsync and StopAsync function to intercept the starting and stopping application events (in the program.cs I've "builder.Services.AddHostedService()" code line). Opening in the browser the http://localhost/app-1 the StartAsync executes, but opening the http://localhost/app-2 the StartAsync doeasn't execute. That is, the (physical) app starts only once.

Changing the AspNetHostingModel from InProcess to OutOfProcess the result is the same. Is there a way to publish multiple instances of webapp pointing the same physycal app executing each separately?

Share edited Feb 13 at 20:24 Dalija Prasnikar 28.6k46 gold badges94 silver badges175 bronze badges asked Nov 29, 2024 at 11:46 AdryoneAdryone 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You do not need to use AddHostedService. The default template code should work fine

public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        // Add services to the container.

        builder.Services.AddControllers();

        var app = builder.Build();

        // Configure the HTTP request pipeline.

        app.UseAuthorization();


        app.MapControllers();

        app.Run();
    }
}

本文标签: cmultiple aspnet core webapi app instances runs only onceStack Overflow