question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use swagger (Swashbuckle ) with ASP.NET core 2.2 and IIS virtual applications

See original GitHub issue

Hi,

I’m currently testing the integration between ASP.NET core and swagger by using the Swashbuckle.AspNetCore nuget package.

My current test environment is the following:

  • ASP.NET core 2.2 web application with one api controller
  • the development machine is a windows 10 machine
  • the installed version of IIS is IIS 10

I’m testing my application by using a virtual application under the IIS default web site. The virtual application has an alias of test-swagger. By following the documentation I configured the swagger middleware in the following manner (notice the . (dot) character at the beginning of the swagger endpoint):

app.UseSwaggerUI(c =>
      {
        c.SwaggerEndpoint("./swagger/v1/swagger.json", "My API V1");
      });

By configuring swagger this way the swagger UI does not work as expected, a pop-up is showed when the path /swagger is called and the message showed states that the swagger UI is not able to find the swagger.json file.

By following this blog I finally solved my issue. Basically, the only difference is that two . (dot) characters are required in the swagger endpoint configuration (while the official docs reports that just one dot character must be used in the swagger endpoint as a prefix).

To summarize, the working configuration for me is the following (notice the two . (dot) characters at the beginning of the swagger endpoint):

app.UseSwaggerUI(c =>
      {
        c.SwaggerEndpoint("../swagger/v1/swagger.json", "My API V1");
      });

Is there an error in the official docs ? Am I missing something ?

Thanks for helping !

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
EnricoMassonecommented, Jun 28, 2019

Have you filed an issue on the Swashbuckle repository?

I’ll try to open an issue directly to Swashbuckle, by referencing this issue. I’ll write here in case of news

1reaction
EnricoMassonecommented, May 31, 2019

It sounds like Swashbuckle isn’t properly using the HttpRequest.PathBase value. Can you provide a sample project that reproduces the problem? What is the full absolute URL you expect for the swagger endpoint?

Hi and apologize for the late reply,

the full absolute URL to which I would like to see the swagger UI is http://localhost/test-swagger/swagger/index.html where test-swagger is the alias assigned to the application registered under the existing web site in IIS. The corresponding URL at which I would expect to find the swagger.json file is http://localhost/test-swagger/swagger/v1/swagger.json.

In this example I have the default IIS website registered to respond at port 80 of localhost and I have registered an application under the default website using the alias test-swagger, as explained above.

These are the steps to reproduce the issue:

  • open visual studio 2017 and create a new ASP.NET core 2.2 web application using the web api template (I’m currently using visual studio 2017 enterprise updated at version 15.9.12)
  • follow this documentation in order to add swagger by using the nuget package Swashbuckle.AspNetCore
  • configure swagger to use directories with IIS as documented in the aformentioned guide by doing this (notice the ./ prefix in the swagger endpoint): app.UseSwaggerUI(c => { c.SwaggerEndpoint("./swagger/v1/swagger.json", "My API V1"); });
  • create an application under the default IIS web site by using the alias test-swagger for the application. Configure the application so that it uses a proper application pool able to run asp.net core applications as documented here.
  • run dotnet publish -c Release and deploy the binaries for the test application in the location chosen for the IIS application configured at the previous point
  • navigate to http://localhost/test-swagger/swagger/index.html. You will get an error when the swagger UI is rendered in your browser.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Get started with Swashbuckle and ASP.NET Core
SwaggerGen : a Swagger generator that builds SwaggerDocument objects directly from your routes, controllers, and models. It's typically combined ...
Read more >
How to fix swagger.json not found in .net core 2.2 app
According to the Swashbuckle docs, you should be able to just use "./swagger/v1/swagger.json" and not prepend the hosting URL. Did that not work ......
Read more >
Build up swagger in asp.net core 2.2 Web API
Swashbuckle is a handy library to easily bring Swagger support to your ASP.NET Core (or ASP.NET) application. It is especially handy when developing...
Read more >
Creating ASP.NET Core Web API with Swagger and Hosting ...
Demo Source Code - https://github.com/greentigerit/MyWebApi References ...
Read more >
Swagger For ASP.NET Core API 2.2
Swagger is a framework which is used to document the Web APIs. In this article, we are going to see how to enable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found