Reputation: 4759
I am working in a web api (.net 5.0) having swagger is enabled. Its working fine when running locally.
But after deploying into azure, its not loading the default page swagger/index.html by default. Instead page cannot be found (404) error is shown. But when I go to the page manually entering the URL its loading correctly and listing all the API end points.
So I went to the app service page and added a new default document in configuration like this
But nothing changed. Still the 404 error when we dont specify the swagger url.
What could be wrong??
Upvotes: 3
Views: 2136
Reputation: 581
This solved the issue - no need to touch the default documents in configuration in app service.
I updated following code in dotnet 6 Program.cs for development and non-development environment separately.
app.UseSwagger();
if (app.Environment.IsDevelopment())
{
app.UseSwaggerUI();
}
if (!app.Environment.IsDevelopment())
{
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
options.RoutePrefix = string.Empty;
});
}
Upvotes: 7
Reputation: 222682
One of the things i missed in the past , check your Startup.cs
file especially the Configure() method.
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 it should work
Upvotes: 3