I tried to create a Webapi in Netcore 2.2 with both Swashbuckle.AspNetCore 5.0.0-rc2 and 4.0.1, the problem is the same. It works in local machine but when I compile a release version and deploy to IIS, I enter the site http://localhost/mysite/ and the error:
Fetch error Not Found /swagger/v1/swagger.json
Also, in the browser, if I enter http://localhost/mysite/swagger/v1/swagger.json I see a Json in OpenApi.
Very simple setup to reproduce:
- create a new webapi project.
- install swashbuckle.aspnetcore 5.0.0-rc2
- change the startup.cs:
public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; }
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
c.RoutePrefix = string.Empty;
});
app.UseMvc();
}
}
- change the .csproj to have the directives:
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.2</TargetFramework> <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> </PropertyGroup> <!-- Enables XML comments on Swagger-UI --> <PropertyGroup> <GenerateDocumentationFile>true</GenerateDocumentationFile> <NoWarn>$(NoWarn);1591</NoWarn> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.App" /> <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" /> </ItemGroup> </Project>
- deploy to IIS and create an application pool.
Any idea of why the lib can't find the swagger.json that is there?