I'm seeing a problem with all our ASP.NET web API projects that we deployed to Azure. The symptom is that when we start the appService, it starts and says it did so successfully. But none of the things that are configured in Startup happen until we try to call one of its endpoints or browse to its swagger page.
For instance, in one, we have a HostedService that connects to our SignalR hub. The hosted service starts up and connects once the Startup methods execute.
But just starting the App Service in Azure portal doesn't kick off the Startup methods, and so Azure says it's running, but it's not connected to SignalR and therefore is not listening for events.
The code I used to create the app's host is this:
return Host.CreateDefaultBuilder(args)
.UseSerilog(ConfigureLogger)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
})
.ConfigureAppConfiguration((context, config) =>
{
if (context.HostingEnvironment.IsProduction())
{
var builtConfig = config.Build();
}
});
Is this a known behavior? Is there something wrong with the above code that is causing the Startup code to not execute until first use of the swagger or endpoint?
Any help would be appreciated.
Thanks
CodePudding user response:
Does your app has Always On
enabled in Azure?
If you go to application settings, there is an always on setting: