I have published web API application(.Net Core 3.1) on IIS under Default Web Site. I have follow the all necessary steps to host .net core application on IIS. Using postman tool I have checked that all API are working correctly.
As I want to show Swagger UI page as startup page after browsing the API from IIS. From IIS whenever I have clicked on [browse:XXX:XXX:XXX:XXX:443 (https) ] link it shows This XXX.XXX.XXX.XXX page can’t be found
browser URL : https://https/XXX.XXX.XXX.XXX/API
Note: If I have added "/" at end of above url then it automatically redirect to swagger's Index.html page.
My existing source code for swagger
public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1.0.0", new Microsoft.OpenApi.Models.OpenApiInfo
{
Title = "TestAPI",
Version = "v1.0.0",
Description = "Test API"
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("./swagger/v1.0.0/swagger.json", "TestAPI V1.0.0");
c.RoutePrefix = "";
});
}
In IIS I have added application by the name (API). I want to show swagger Index.html page as default page after accessing from IIS.
I don not understand that anything is missing at code level or need to do any setting on IIS to display default swagger page.
Additional Information:
Swagger Package: Swashbuckle.AspNeteCore(5.3.1)
OS: Windoes 10
IIS : 10.0.19041.1
Note: Same API I have published as NewWebSite(Not under Default Web Site) on IIS then it works as par expectation.