Swagger UI page is blank on localhost SSL Url - swagger

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:
IISExpress App URL: http://localhost:64870
IISExpress Enable SSL URL: https://localhost:44387/
Console http://localhost:5000 and http://localhost:5001
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

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

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.

Related

(Routing problem) Hosting .NET Core 5.0 MVC application on IIS

I am having a problem when I deploy a WebApi and/or ASP.NET MVC application targeting the .NET 5 framework.
I created the Site and Application Pool and set the bindings as well. The Application Pool is set to No Managed Code and the Pipeline is set to Integrated.
I am using the same configurations as we use for all other .NET Core 3.x applications - we have 20-30 applications and WebApis.
I am getting a 404 error from the server when I try to open the URL. I figured out that there has to be a routing problem. When I call as specific action (https://myurl/home/index) I do get the correct response from the server.
I installed the ASP.NET Core Runtime 5.0.0 (Hosting Bundle) on the IIS webserver. Initialy I was getting this error with my .NET 5 WebApi I started to create with .NET 5 RC1.
So I created a new default MVC application and deployed it to the same server. Same issues here.
With the IIS Express localy it works just fine.
Any ideas?
I found the root of the problem.
A newly created .NET 5 web api project hides swagger by default if the environment is not development:
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Version 1.0");
c.RoutePrefix = string.Empty;
});
}
This is of course the reason why the wep api itself works (e.g. with postman) but why we get a 404 error when trying to open Swagger in the browser.
So in my case I disable Swagger only in production:
if (!env.IsProduction())
{....}

React.js ASP.NET MVC core app hosted in IIS cannot read API (Controller) 404

I have been trying to access the controller methods (API) of my MVC.NET Core react application hosted on IIS. The application works perfectly except when fetching data from the API.
I am using the template project that visual studio 2019 creates. If I debug locally, the controller can be accessed. I have tried adding rules to the web.config and some working some settings in app.UseMvc(Routes).
Request URL:http://localhost:xx/api/SampleData/WeatherForecasts
Request method:GET
Status code: 404
Version:HTTP/1.1
Referrer Policy:no-referrer-when-downgrade
fetch('api/SampleData/WeatherForecasts')
.then(response => response.json())
.then(data => {
this.setState({ forecasts: data, loading: false });
});
The controller has the route : [Route("api/[controller]")]
It seems that it is trying to find a folder that has the path above and it its not finding it.
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Has somebody encountered this? I want to get my app fully working in IIS before I star developing it. Thanks!
When you deploy the app on IIS "usually" it runs on the default port 80 or 443 if https. Maybe your request is hitting the port you are using during development.
When on IIS try to remove the :xx part of your url
I resolved the problem. I did not have .NET Core Run-time Installed on the server machine. https://dotnet.microsoft.com/download
To host the app in IIS it has to be pointing to the publish folder where your {application}.dll exist. From there it will read the config file and start the UI with the back-end.
open terminal (on your project), run: iisexpress-proxy 5000 to 5001
and run your link.
good luck!
my issue is with React, what happens is the url of the api becomes "localhost:80/client/build/api" something....

Chrome Says "This webpage is not available" When I Run My MVC Project as http

Visual Studio 2013 Update 3 and IIS 8.5
I started an MVC 5 project and have been messing around with ssl. Everything worked great until I opened IIS and added a website that pointed to my project. Now, I can run the project with ssl enabled but NOT with it disabled. If I disable ssl, I get the following Error Message in Chrome.
I'm fairly certain my project is setup correctly in Visual Studio. "SSL Enabled" is false and the "Project Url" is http://localhost:#####/ straight form the project's properties.
When this started happening, I figured it was IIS and so I deleted the Site from IIS. This obviously did not fix it. So I tried looking online but couldn't find anything helpful. The only other ounce of information is a photo of the request being redirected in Chrome's network window.
Keep in mind when I run locally with ssl, everything works fine.

Breeze sample does not work in IE

I create a MVC 4 application (WebAPI or empty) and I load the Breeze NuGet packages and hit F5 like they say I should, if I run in Google Chrome or Page Inspector all goes well, if I run in the current IE 10 I get an exception on the last line:
(function (root) {
var ko = root.ko,
breeze = root.breeze,
logger = root.app.logger;
// service name is route to the Web API controller
var serviceName = 'api/BreezeSample';
// manager is the service gateway and cache holder
var manager = new breeze.EntityManager(serviceName);
Essentially root.breeze is undefined, any idea why this is happening? How would the browser influence that?
How would I fix it? (I'm using VS 2012 Express for Web with all the updates loaded)
Adriaan,
I tried to replicate your error but could not. Here are the steps I used to get it up and running in IE10 (also using VS Express 2012 for Web):
File
New Project...
ASP.NET MVC 4 Web Application (Visual C#)
Empty
Tools
Library Package Manager
Manage NuGet Packages for Solution...
Search for Breeze.
Install Breeze for ASP.NET MVC4 Web Api Sample.
Ok
I Accept
Close
F5
Everything worked as expected.
I know it isn't the same error you are having, but if it makes you feel better, I failed out the first time I tried this as I selected ASP.NET MVC 4 Web Application (Visual Basic) instead of the C# version. Sure to fail and embarrassing once I realized the mistake.

Unable to start debugging on the web server. The web server could not find the requested resource

I'm having this error trying to debug my ASP.NET MVC app. I've set the app to "Use Local IIS Web server", and selected ASP.NET as the debugger. Running the site without debugging works just fine, but when I try to debug, I got this error:
Unable to start debugging on the web server. The web server could not find the requested source.
I'm using Visual Web Developer 2008 Express Edition.
Does anyone know how to fix this error? Thank you.
For those encountering this with Visual-Studio 2012 and/or Windows 8 do the following.
You have to add .Net 3.5 (or 4.5) to your Turn Windows Features on or off window. You get to it via :
Control Panel -> Programs -> Turn Windows Features on or off
Click the Asp.Net 3.5 and the Asp.Net 4.5 check box in the IIS > WWW Service > Application Development Features folder.
Go to your web project's properties, then the "web" tab, then make sure that you're using the Visual Studio Development Server and not Local IIS or the custom webserver. I'm on VS2010 with Win7 and another developer was developing using a custom webserver URL and not the VS Dev Server
Sounds like you are trying to develop on IIS and not iis express or development server. If you are using asp.net mvc 4, make sure that the Application Pool is framework 4. If not just make sure that your app pool it matches your asp.net mvc version.
I had the same problem, and i fixed this way:
Go to IIS Manager -> Go to the site -> Error Pages -> Actions: edit feature settings.. -> Make sure you checked "detailed errors for local requests and custom error pages for remote requests".
IF you are using IIS6 and did the add mapping for .* in IIS trick to get MVC working, when you added the .* handler to iisapi.dll you forgot to uncheck the "check the file exists" check box.
Also, be sure that the URL you're configuring in Visual Studio matches your Host Headers (Edit Bindings) in IIS. This tripped me up for about an hour this morning before I realized my very stupid error.
Having maxRequestLength or maxAllowedContentLength set to a ridiculously large or small value will also trigger this error.
What i did, was just type the IP address in the web tab instead of "localhost"
This happened to me today. Turned out to be that the default website was stopped in iis. I had been working on a second website that didn't use it for a long time. Simple fix but took me a while to see it!
The root cause for this error can often be that the Windows Service W3SVC is not started. Check that this service in Windows Services console (services.msc) is started. In IIS you will now see the the Start icon is greyed out. This means that the W3SVC service is running.

Resources