I'm deploying an ASP.NET Core 8 Web API app with deliberately failing startup code to a Windows Azure App Service with the S1 plan.
The https endpoint does return 500.30 indicating the failed startup.
But the Status of the app service on the Azure Portal is "Running" which is confusing.
I would expect it to be in a failed status which does happen for Azure Functions.
Is there anything in my code/app service setup/deployment that I can change for the Status to reflect that the startup has failed?
I'm deploying via Visual Studio with the following publish profile:
Configuration: Release
Target framework: net8.0
Deployment Mode: framework-dependent
Target Runtime: Portable
Sample reproduction code: https://github.com/Aleksey-Kudryavtsev/StartupFailureAspNetCore
App Service Status Running with failed startup
The status of the App service is not based on the code/any exceptions thrown.
It will be based on the availability of the resources used, but not on the exceptions/startup errors.
Remove throw new ApplicationException("Test startup failure");
line from your Program.cs
file.
Is there anything in my code/app service setup/deployment that I can change for the Status to reflect that the startup has failed?
AFAIK, there is no such way to change the running status of the app directly.
You can configure Azure Health checks to handle it.
UseExceptionHandler
and UseStatusCodePages
.I am able to handle the exception by using the below code.
Thanks @George for the clear steps.
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseStatusCodePages("text/plain", "Exception, status code: {0}");
Output: