title: ASP.NET Core Swagger uses incorrect json url when web application is hosted in a subdirectory
body: <p>I followed <a href="https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger" rel="nofollow noreferrer">these instructions</a> to add swagger to my ASP.NET Core application.</p>
  
  <p>It works fine when I host it as a root website but when I host the app as an alias on an existing website, say <code>myserver.com/myapp</code>, swagger will look for <code>swagger.json</code> at an incorrect URL and report: *Can't read swagger JSON from <code>https://myserver.com/swagger/v1/swagger.json</code>. It should instead use <code>https://myserver.com/myapp/swagger/v1/swagger.json</code>.</p>
  
  <p>The message I get is:</p>
  
  <blockquote>
    <p>Can't read swagger JSON from <a href="https://myserver.com/swagger/v1/swagger.json" rel="nofollow noreferrer">https://myserver.com/swagger/v1/swagger.json</a></p>
  </blockquote>
  
  <p>How can I configure swashbuckle/swagger to use the application base path and look for the swagger.json file at the right place?</p>
  
  <p>I'm hosting on IIS.</p>
  
  <p>The version of swashbuckle is:</p>
  
  <pre><code>"Swashbuckle": "6.0.0-beta902"
  </code></pre>
  
  <p>I suspect that I'll have to add something to the <code>app.UseSwaggerUi()</code> in the <code>Configure</code> method in <code>Startup.cs</code> but I'm not sure what.</p>
  
  <p><strong>Startup Configure</strong>:</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  {
      loggerFactory.AddConsole(Configuration.GetSection("Logging"));
      loggerFactory.AddDebug();
  
      if (env.IsDevelopment())
      {
          app.UseDeveloperExceptionPage();
          app.UseBrowserLink();
      }
      else
      {
          app.UseExceptionHandler("/Home/Error");
      }
  
      app.UseStaticFiles();
  
      app.UseMvc(routes =&gt;
      {
          routes.MapRoute(
              name: "default",
              template: "{controller=Home}/{action=Index}/{id?}");
      });
  
      // Enable middleware to serve generated Swagger as a JSON endpoint
      app.UseSwagger();
  
      // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
      app.UseSwaggerUi();
  }
  </code></pre>