DotNet 5.0 Swagger is not loading in Azure App Service

Viewed 3701

i have a web api which is created using dotnet 5.0 and deployed to Azure App Service, It is running and swagger loads successful, but in Azure App Service the swagger is not loading also throws 404 error but API data loads successfully.

1 Answers

Check your Startup.cs file and the Configure() method.
If you created a new .NET 5 project with Swagger automatically configured then it may only be enabled in the development environment.
Check if your code looks something like this:

if (env.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Lotus.API.Integration v1"));
}

Move the Swagger configuration lines outside the if statement and that should allow it to load in Azure (i.e. outside of your IDE).

Related