Not able to see swagger in IIS .Net Core

Viewed 167

I am currently developing Web Api .net core 5.0 with swagger. I have hosted my application in IIS.I am able to see my Web APi working but my swagger is not responding.

 services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo { Title = "TestWebApi", Version = "v1" });               
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    In = ParameterLocation.Header,
                    Description = "Please insert JWT with Bearer into field",
                    Name = "Authorization",
                    Type = SecuritySchemeType.ApiKey
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement {
   {
     new OpenApiSecurityScheme
     {
       Reference = new OpenApiReference
       {
         Type = ReferenceType.SecurityScheme,
         Id = "Bearer"
       }
      },
      new string[] { }
    }
            });
        });

Also in configure services I have used double dots as mentioned solutions in one of the forums.GitHub

 app.UseSwaggerUI(c => c.SwaggerEndpoint("../swagger/v1/swagger.json", "TestWebApi v1") 
                
                );

I tried checking the web api as localapi but I am getting 404 error.

Thanks

1 Answers

app.UseSwaggerUI was in condition that isDevelopment loop. For this reason it was working in VS 2019 but not in IIS deployment.

Related