ASP.NET Core This localhost page can’t be found
Issues encountered while hosting ASP.NET Core Web API on IIS for the first time
It might seem like a minor issue, but it took me two days to debug! :(
The firm I worked with had been using .NET 4.5 for over four years (shocking, right!?). This year, we decided to upgrade to .NET Core. Since it was my first time, I chose to do a local publish before deploying it on our server. We also use Swashbuckle for API documentation, which was part of the issues I encountered.
After publishing to my local IIS Server, I encountered an HTTP error 404. I initially thought the issue might be with:
The
appsettings.json
file, orThe
web.config
file
I spent two days adjusting those files without success. It turned out my attention should have been on my program.cs
file. Interestingly, I used ChatGPT to help troubleshoot the error and tried the suggestions, but they didn't work (I felt a bit foolish, lol).
Why didn't I think of checking my program.cs
file? I have no idea!
From the snippet above, I was using the production environment, yet, expecting to swagger ui to display
. Huh!
I updated my code to:
Since my app runs on port 2000, I expected that after starting my app on this port, the swagger ui
would display automatically, even without specifying the swagger endpoint (I had a good laugh at my assumption). However, I still received a 404 error.
For my final configuration, I set the route prefix to an empty string so that swagger ui
would display when accessed from port 2000 after being hosted on IIS.
I'm happy to say my swagger ui
now displays as expected without the 404 error after hosting on my local IIS.
Here is my final configuration:
With that, I successfully published my app on IIS!
When the RoutePrefix is set in development mode, you might encounter another "page not found" issue.