title: How to fix swagger.json not found in .net core 2.2 app
body: <p>I'm deploying my .net core app on IIS server and facing the issue in swagger UI where swagger.json not found. When I run it locally (Development environment) everything is working perfectly but when I deploy it on IIS server it fails to find swagger.json file.</p>
  
  <p>Previously I was facing this issue in .net core 2.1 app and I resolved it by writing below code to get the virtual base path.</p>
  
  <pre><code>string basePath = Environment.GetEnvironmentVariable("ASPNETCORE_APPL_PATH");
              basePath = basePath == null ? "/" : (basePath.EndsWith("/") ? basePath : $"{basePath}/");
  
   app.UseSwaggerUI(c =&gt;
       {
        c.SwaggerEndpoint($"{basePath}swagger/v1/swagger.json", "Test.Web.Api");
        c.RoutePrefix = "";
       });
  </code></pre>
  
  <p>I have tried below code to resolve it:</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env)
   {
     app.UseSwaggerUI(c =&gt;
       {
        c.SwaggerEndpoint($"{env.ContentRootPath}swagger/v1/swagger.json", "Test.Web.Api");
         //OR
        c.SwaggerEndpoint($"{env.WebRootPath}swagger/v1/swagger.json", "Test.Web.Api");
        c.RoutePrefix = "";
       });
   }
  </code></pre>
  
  <p>But abouve code didn't worked as it returns actual physical path and not virtual path.</p>
  
  <ul>
  <li><strong>An output of the above code</strong>: C:/inetpub/wwwroot/myapp/swagger/v1/swagger.json</li>
  <li><strong>Expected output</strong>: <a href="http://myserver/MySite/swagger/v1/swagger.json" rel="noreferrer">http://myserver/MySite/swagger/v1/swagger.json</a></li>
  </ul>
  
  <p>Does anyone know how to get the virtual path in .net core 2.2 as <code>Environment.GetEnvironmentVariable("ASPNETCORE_APPL_PATH");</code> is not working. Any lead would be helpful.</p>