问题
I have a ASP.NET Web API implemented as OWIN middleware. I hosted it on azure and now I have a problem using swagger. It is perfectly working on localhost but when I try it on azure I get this:
The way I did my configuration for swagger on the API was to completely remove SwaggerConfig.cs file and add all the configuration into my Startup.cs class as shown here: How to generate documentation using swashbuckle for WebApi 2 with Owin . If it is going to help, I am trying to implement oAuth2 between my API, identity server and client application.
Can you help me find out what is the reason for not getting swagger functionality on Azure?
EDIT: I also tried the solution from here but without success. I went to my API->Properties->Buld tab->Changed to 'Release' configuration->In the output path added the same what was in the 'Debug' configuration and nothing.
My bin folder on Azure:
回答1:
I had this problem myself when going though this tutorial.
In that tutorial on #3 under "Configure the middle tier to call the data tier" I named my key apiAppURL instead of toDoListDataAPIURL. This caused me to get 500 response codes and
{
"Message": "An error has occurred."
}
in the response body.
I fixed it by updating the following line:
var client = new ApiApp(new Uri(ConfigurationManager.AppSettings["toDoListApiURL"]));
to
var client = new ApiApp(new Uri(ConfigurationManager.AppSettings["apiAppURL"]));
**The change made was to the string at the end of the line. That code can be found in ToDoListController.cs on line 42
Hope this helps someone!
回答2:
Check your SwaggerConfig.cs file, if you are not included the xml file with your swagger, it works in your azure app services.
c.IncludeXmlComments($@"{System.AppDomain.CurrentDomain.BaseDirectory}\bin\WebApiSwagger.XML");
c.DescribeAllEnumsAsStrings();
I've included these 2 lines of code to show my xml in the swagger, the azure swagger will gone error.
回答3:
This is late reply but may help someone in future. I solved this issue this way:
- Set XML documentation file path in project settings to : wwwroot\api.xml
Let Swagger know where the file is within ConfigureServices method in Startup.cs:
services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); // Set the comments path for the Swagger JSON and UI. var xmlFile = "api.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", xmlFile); c.IncludeXmlComments(xmlPath); });
You can set different paths but you will get the idea of how to do it from this example.
来源:https://stackoverflow.com/questions/39406820/swagger-not-working-on-azure-web-app-running-as-owin