Here's what I've tried so far:
- Made the default "ASP.NET Core API" project (the weather forecasting one) in Visual Studio
- Built it and copied the contents of the build folder to C:\Users\[My username]\TestService
- Ran the TestService executable. It says "Now listening on: http://localhost:5000"
- Open my browser, enter the "http://localhost:5000" URL. I get a 404 error. This is all on the same computer.
- Noticed that, under launchSettings.json, there were some other URLs listed, none of them localhost:5000. It gives 2 https URLs: https://localhost:7079 and http://localhost:5222. Both of these give "connection refused" errors.
- At this point, I don't know what else to do
Please help I don't want to lose my job
EDIT: I was able to figure out what was going on. Solution is here. Thanks to hypercracker and everyone else who advised
I don't know the specifics of this example project (and am honestly too lazy to replicate it on my own computer) but here is my debugging process for stuff like this:
- You got a 404 response, which is different from the nothing-ness response you'd get from going to like localhost:12345 or some random port. This means that a web service is actually listening on port 5000, receiving your request, and serving you a 404 page; is any logging happening on the console when you access this page?
- Are you supposed to access your app over a web browser (like it serves an HTML page) or is it a REST API that you would use a different tool to access (usually a browser extension or some CLI tool)?
- If you're supposed to access your app over a web browser, try going to localhost:5000/index.html or something
- None of your https endpoints will be set up by default probably, but anyway you can't listen over https (aka SSL aka TLS) without having some kind of a certificate, self-signed or otherwise; usually for local testing you set up a self-signed cert which when visited in the browser will take you to the "connection not secure" page since your browser doesn't trust random certs, only those that can be chained back to a root of trust (aka big companies like microsoft or LetsEncrypt)
- You got a 404 response, which is different from the nothing-ness response you'd get from going to like localhost:12345 or some random port. This means that a web service is actually listening on port 5000, receiving your request, and serving you a 404 page; is any logging happening on the console when you access this page?
- Are you supposed to access your app over a web browser (like it serves an HTML page) or is it a REST API that you would use a different tool to access (usually a browser extension or some CLI tool)?
- If you're supposed to access your app over a web browser, try going to localhost:5000/index.html or something
THANK YOU! This helped me figure it out. I looked in the TestService project and found TestService.http with the following contents:
@TestService_HostAddress = http://localhost:5222
GET {{TestService_HostAddress}}/weatherforecast/
Accept: application/json
So I tried going to http://localhost:5000/weatherforecast and that opened the page.
Oof I know nothing about .NET but I'll look
One thing you might want to try is running visual studio as admin? (taken from the readme of this github)Honestly idk if this is it because:404 error means you did reach a listening web server, just that the url doesn't exist.
It's a missing endpoint implementation problem
The other comment mentioning this goes into a lot more details than mine
yeah they beat me by like a minute, didn't see that til I refreshed. It wasn't so much missing as he was browsing to the wrong url for the example code
lol I got a Master's Degree without figuring out any of this shit. Not sure whether that says something about me or about American post-secondary education
mostly the latter lol
Its not all bad, but they really don't mix the high-level theory and the practical skills very well in my limited experience. Maybe that's intentional.
Can you link that default server code?
404 means your browser was able to successfully ping your server and get a response, but there wasn't an endpoint implemented for the one you hit
Maybe it's missing a GET for the default empty endpoint