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 badges1 Answer
Reset to default 0You 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
版权声明:本文标题:c# - multiple asp.net core webapi app instances runs only once - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742261315a2442566.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论