Reputation: 353
I am developing a v5.0.6 ASP.NET Core WebApi and included Swashbuckle.AspNetCore Swagger with SwaggerUI enabled. I am developing with Visual Studio 2019 v16.10.0 on Windows 10 Version 21H1 (OS Build 19043.1023). Settings within the project properties are:
If I start the WebApi from VS2019 and it comes up with URL 'https://localhost:44387/' the SwaggerUI page is completely blank but the WebApi can be accessed and data can be retrieved So I know the WebApi is working as it should. I can access the WebApi from any of the other URLs and the SwaggerUI page is displayed as it should be. It is only the IISExpress SSL URL of 'https://localhost:44387/' that has the empty page. I have spent hours working on this issue with no solution.
Has anyone seen this issue and has a solution.
Update: I had to replace one of my other development machines with a new Dell 8940 Desktop so I installed all the development software. Used GitKraken to pull down the source code. Started up Visual Studio 2019, opened the blog solution. After that I started the blog with it's associated API on the new machine and the SwaggerUI worked just perfect. So there is something peculiar about the other machines settings. Not sure what that is but I wish I could figure it out as that machine is my primary development machine.
Anyone have any ideas?
Update: Updated my project to Swashbuckle v6.1.5 and everything is working again. Swagger UI is now loading as it should. Hmmmm....
Steve
Upvotes: 0
Views: 4497
Reputation: 1
Check whether loading the swagger-ui-standalone-preset.js file is blocked by anti-virus software. Because this file was not loaded, a jscript error was shown as follows:
Uncaught ReferenceError: SwaggerUIStandalonePreset is not defined
In my case, I found that it is not working only in the Microsoft Edge browser. SSL worked with Chrome and Firefox.
Upvotes: 0
Reputation: 1119
It's hard to say what the issue is.
Try adding the nuget package Swashbuckle.AspNetCore.SwaggerGen.
In Startup.cs 'ConfigureServices' add this:
services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new Microsoft.OpenApi.Models.OpenApiInfo()
{
Title = "My Api",
Version = "1.0"
});
});
And in Startup.cs 'Configure' add this:
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My Api v1");
});
And then navigate to https://localhost:44387/swagger
Upvotes: 0