Swagger UI not loading in Azure Containers

Summary

After deploying a new Web API project from within Visual Studio you may notice that you cannot launch the Swagger UI after a deployment to Azure Container. This is because the Visual Studio Web API template adds the Swagger methods to the Development pipeline and not the Production.

To enable this for Production use, add an else condition or place the swagger methods outside the IF statement.

Enable Swagger UI

To get to the UI update the StartUp.cs class or Program.cs from:

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
    app.UseSwagger();
    app.UseSwaggerUI();
}

To this:

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
    app.UseSwagger();
    app.UseSwaggerUI();
}
else if (app.Environment.IsProduction())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

Now you should be able to browse to the Swagger UI.