โ Frontend unable to connect to webapi when starting server manually (dotnet run)
When I run my C# Webapi project through Visual Studio Code debugger (or VS) then my reactapp can make a GET request to the webapi, however if I start up the webapi via cmd
dotnet run
and make a GET request I get net::ERR_CONNECTION_REFUSED
This is the output from VS Code when I start the webapi through the debugger.
This is the output from cmd when I start the webapi through the cmd.
22 Replies
can u show details about the request itself? url and port most
i can think of 4 issues here:
- wrong port/scheme
- wrong hostname
- firewall is blocking the connection (tho this would be a bit weird cuz it should block the server itself then which would be shown in the logs of the
dotnet run
command)const testResponse = await fetch('https://localhost:7045/api/insurancecalculator/getCalculation/' + JSON.stringify(extractedData));
It says 7045
but both methods of connecting to server listen on 5206
and when I try to start the server via the debugger (which works) when I have the cmd method running it complains that 5206
is being used.Well obviously the request needs to be sent to a port the server is listening on.
Also sounds like you have another server running - check task manager etc
It complains that 5206 is being used (when I do debug method) if I run dotnet run via cmd first. Otherwise, if the debug method is just running alone then it is using 5026 but is able to make the GET request which has port 7045, hence I don't see the issue being here.
when i do debug methodwhat do u mean by this? starting via
dotnet run
and then pressing the "Start Debug" button in visual studio?
also its most likely occupying both ports, one for http and one for httpsDefault Configs would normally pick consecutive ports for http/https
More likely they're running different profiles without realising
i cant test right now, wouldnt asp.net core also log both ports when running
refering to this log
That is the debug method of starting the server (which works), and
dotnet run
in cmd is the other method (which doesn't)
Oh, I ran netstat -an | find "LISTENING"
in cmd and the ports 5206
and 7045
show up via the debug method but only 5206
via the cmd method. 7045
isn't starting.well, it certainly sounds like u first start via
dotnet run
and then (while its still running) try to start the debug process and thus it complains the ports are already taken
so 7045 is definitively the https port.
can u show ur application settings json files?
dont forget to censor/remove any tokens or other sensible data firstYes, that was me just testing to see if the same ports
5206
via both methods were both being used.
The problem is 7045
is not also running via cmd.
I'm not sure if anything is sensitive info.nah its not
what happens if ya run
dotnet run -c Debug
(might have to be Development
)?
maybe its just not using http due to release configuration and thats the whole issueNo difference to
dotnet run
hmm then im out of ideas right now, would have to have access to a computer w/ vs and dotnet installation, and i probably wont have within the next 24h ๐
Ok, no worries. Thanks for your help anyways.
When I run with Visual Studio (not Code) I get this output. Contains 7045.
yeah for any reason the
dotnet run
doesnt use the https configuration as well, my guess was because of "ASPNETCORE_ENVIRONMENT": "Development"
and it may be running in release configuration (hence the tries with Debug/Development)GitHub
dotnet run command not listening on https ยท Issue #29569 ยท dotnet/s...
Describe the bug I am running a simple webapi program on Windows and when I try to run the 'dotnet run' cli command, I can see it's listening only on http but not on https. I have also ...
so if u would switch the order of the http and the https profile it would already be enough
It works!
dotnet run --launch-profile https
Thank youglad i could help, a bit of using a search engine sometimes works wonders ๐
lol been using chatgpt, though to be fair it did talk about profiles which I was going to try to do later, that I just found out about now.
tbh, chatgpt isnt that useful in most cases. its relatively good for beginner stuff. i used it alot for my getting-started-with-avalonia stuff because there werent many resources around, the answers were still quite broken, but i was able to adapt.
for such cases it is relatively good, but for details or anything beyond their time of fetching internet resources (iirc that was 2021) its doing more damage than anything
and dotnet 7 was released last year, so it doesnt have any valuable information regarding that
if ur question is now fully answered please dont forget to mark this thread as answered by $close ing it
Use the /close command to mark a forum thread as answered