I created an Asp.Net Core 2.x Web API and configured Swagger on it, below is the code added in Configure method under Startup.cs file, for full swagger configuration, check here
//Add swagger configuration 
app.UseSwagger(); 
app.UseSwaggerUI(c => 
{ 
    c.SwaggerEndpoint("../swagger/v1/swagger.json", "Test API V1"); 
}); 
 | 
 
On my local machine when I run the API it is automatically redirected to the Swagger page.
However, when I hosted this API as an Azure web app it is not redirecting directly to the Swagger and to access the swagger, I had to append /swagger in the URL, for example, https://testapi.azurewebsites.net/swagger/
Solution:
Set RoutePrefix to string.Empty under app.UseSwaggerUI like below:
app.UseSwaggerUI(c => 
{ 
    c.SwaggerEndpoint("../swagger/v1/swagger.json", "Test API V1"); 
    c.RoutePrefix = string.Empty;// Set Swagger UI at apps root 
}); 
 | 
 
And that’s it, now when you browse the Azure web app, it’ll
automatically redirect you to the Swagger page.
Comments
Post a Comment