title: Swashbuckle Error - 404 for 'swagger.json' when running in IIS
body: <p>I have a basic asp.net core 5.0 web API. I installed Swashbuckle.ASPNetCore swagger-5.6.3 nuget package.</p>
  <p>here is my startup.cs.</p>
  <p>startup.cs:</p>
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      #region Api Versioning
      services.AddVersioning();
      #endregion
      #region Swagger
      services.AddSwagger();
      #endregion
  }
  
  public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, IApiVersionDescriptionProvider provider, UserManager&lt;ApplicationUser&gt; userManager, RoleManager&lt;ApplicationRole&gt; roleManager)
  {
      app.UseMiddleware&lt;ExceptionMiddleware&gt;();
      app.UseStatusCodePagesWithReExecute(&quot;/errors/{0}&quot;);
      #region Swagger
      // Enable middleware to serve generated Swagger as a JSON endpoint.
      app.UseVersionedSwagger(provider);
      #endregion
      #region CORS
      app.UseCors(&quot;AllowAllOrigins&quot;);
      #endregion
      app.UseHttpsRedirection();
      app.UseRouting();
      app.UseAuthentication();
      app.UseAuthorization();
      app.UseEndpoints(endpoints =&gt;
      {
          endpoints.MapControllers();
      });
  }
  </code></pre>
  <p>Here are the details:</p>
  <pre><code>public static class ApiVersioningExtension
  {
      public static IServiceCollection AddVersioning(this IServiceCollection services)
      {
          services.AddApiVersioning(
              options =&gt;
              {
                  options.ReportApiVersions = true;
              });
          services.AddVersionedApiExplorer(
              options =&gt;
              {
                  options.GroupNameFormat = &quot;'v'VVV&quot;;
                  options.SubstituteApiVersionInUrl = true;
              });
  
          return services;
      }
  }
  
  private static string XmlCommentsFilePath
  {
      get
      {
          var basePath = PlatformServices.Default.Application.ApplicationBasePath;
          var fileName = typeof(Startup).GetTypeInfo().Assembly.GetName().Name + &quot;.xml&quot;;
          return Path.Combine(basePath, fileName);
      }
  }
  
  public static IServiceCollection AddSwagger(this IServiceCollection services)
  {
      services.AddTransient&lt;IConfigureOptions&lt;SwaggerGenOptions&gt;, ConfigureSwaggerOptions&gt;();
  
      services.AddSwaggerGen(options =&gt;
      {
          options.OperationFilter&lt;SwaggerDefaultValues&gt;();
  
          options.AddSecurityDefinition(&quot;Bearer&quot;, new OpenApiSecurityScheme
          {
              Scheme = &quot;Bearer&quot;,
              Description = @&quot;JWT Authorization header using the Bearer scheme. &lt;br&gt;&lt;br&gt; 
                Enter 'Bearer' [space] and then your token in the text input below.
                &lt;br&gt;&lt;br&gt;Example: 'Bearer 12345abcdef'&quot;,
              Name = &quot;Authorization&quot;,
              In = ParameterLocation.Header,
              Type = SecuritySchemeType.Http
          });
  
          options.OperationFilter&lt;SwaggerAuthorizeCheckOperationFilter&gt;();
  
          // integrate xml comments
          options.IncludeXmlComments(XmlCommentsFilePath);
      });
  
      return services;
  }
  
  public static IApplicationBuilder UseVersionedSwagger(this IApplicationBuilder app, IApiVersionDescriptionProvider provider)
  {
      app.UseSwagger();
      app.UseSwaggerUI(
          options =&gt;
          {
              foreach (var description in provider.ApiVersionDescriptions)
              {
                  options.SwaggerEndpoint($&quot;/swagger/{description.GroupName}/swagger.json&quot;, description.GroupName.ToUpperInvariant());
              }
          });
  
      return app;
  }
  
  public class SwaggerDefaultValues : IOperationFilter
  {
      public void Apply(OpenApiOperation operation, OperationFilterContext context)
      {
          var apiDescription = context.ApiDescription;
  
          operation.Deprecated |= apiDescription.IsDeprecated();
  
          if (operation.Parameters == null)
          {
              return;
          }
  
          foreach (var parameter in operation.Parameters)
          {
              var description = apiDescription.ParameterDescriptions.First(p =&gt; p.Name == parameter.Name);
  
              if (parameter.Description == null)
              {
                  parameter.Description = description.ModelMetadata?.Description;
              }
  
              if (parameter.Schema.Default == null &amp;&amp; description.DefaultValue != null)
              {
                  parameter.Schema.Default = new OpenApiString(description.DefaultValue.ToString());
              }
  
              parameter.Required |= description.IsRequired;
          }
      }
  }
  </code></pre>
  <p>When I run this on IIS Express, swagger is working fine. Then I deployed this to IIS, I am getting 404 not found.</p>
  <p>This works:</p>
  <blockquote>
  <p>http://localhost/myapp/swagger/v1/swagger.json</p>
  </blockquote>
  <p>But,</p>
  <blockquote>
  <p>http://localhost/myapp/swagger/index.html</p>
  </blockquote>
  <p>gives the error:</p>
  <blockquote>
  <p>Errors Hide Fetch errorNot Found /swagger/v1/swagger.json</p>
  </blockquote>
  <p>How do I resolve this?</p>