c# - multiple asp.net core webapi app instances runs only once - Stack Overflow

I've an asp core 8.0 webapi published on two IIS app (the OS is Windows 11), named app-1 and app-2

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();
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742261316a4410958.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信