❔ ✅ Swagger page doesn't load in fresh generated 7.0 .net webapi
The API itself works, I can create, query, and access new endpoints in the browser. But the swagger UI either isn't hosted or generated at all (404 not found)
My only hint is this warning when I try to load the page: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3] Failed to determine the https port for redirect
...Which disappears when I comment out app.UseHttpsRedirection(); in Program.cs.
Anyone come across this before? Maybe someone could share their config or program.cs?
35 Replies
The application doesn't seem to be freshly generated. There have been some modifications. Try this and navigate to
localhost:port/swagger
when running.Yes, c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); on line 22 was added in an attempt at troubleshooting. Removed it again, same result on http://localhost:5132/swagger
here's my launchsettings for good measure
this is the program.cs for a freshly generated web api
if you remove your alterations to SwaggerGen and SwaggerEndpoint, does that help?
Nope, same result. Note that I've already tried the fresh version, my alterations have been done to troubleshoot.
very weird, since the fresh template works
I can try to generate another new project
yeah just
dotnet new webapi -n DeleteMe
and run it straight up, not a single line of code modifiedwill do
if that doesnt work, something is very weird
DeleteMe? what's this
just the name of the new project 🙂
oh lol
-n
gives it a name via the CLI and creates it in a new subfolder
instead of generating the project where you arestill the same
Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.
warning when trying to access root url
and http://localhost:5113/swagger
well, you shouldn't be accessing it on HTTP
how are you running it?
dotnet run
it defaults to http apparently
okay. you can make it use https by default by re-ordering the profiles - or use
dotnet run --launch-profile https
this is with https in url
that worked
but still the same 404 in browser
https uses a different port
make sure you are accessing the correct url
yes it's on https://localhost:7289
Don't take this the wrong way, but you must be doing something wrong :p
are you sure you dont have another instance of the program running already, causing binding failures?
or another app using those ports
Not that I know of. Gonna make sure
brb rebooting
Nah still nothing
only thing I can think of now is that I had to manually set my environment variable for the 7.0 SDK to generate a project
setting it to C:\Program Files\dotnet\sdk\7.0.203\Sdks after installing 7.0 sdk
but I can generate the project so clearly that works
Noticing something else in my env variables: %USERPROFILE%.dotnet\tools --- C:\Users\peter.dotnet doesn't have any tools folder
idk if that's relevant
probably not for this
tools is like a "plugin" for the
dotnet
cligotcha
Can you jump into #dev-vc-1 and share screen btw?
sure
Solved -
DOTNET_ENVIRONMENT
was set to an unexpected value which caused app.Environment.IsDevelopment()
to say falseWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.