localhost refused to connect Error in visual studio
Solution 1
I had a similar issue. Try this and it should work
Go to your project folder and open the
.vs
folder (keep your check hidden item-box checked as this folder may be hidden sometimes)In the
.vs
folder open theconfig
folderSee that
applicationhost.config
file there? Delete that thing. (Do not worry it will regenerate automatically once you recompile the project.)
Solution 2
Usually on local machine we are getting errors like This site can't be reached localhost refused to connect
because we have self signed certificate configuration broken for local IIS Express. Sometimes it happens when you change URLs in launchSettings.json
or never configured self signed certificates on this machine at all.
To fix self-signed certificate on the local machine you need to:
- Delete .vs folder (requires to close Visual Studio 2017)
-
Run these commands in
cmd
As Administrator
:cd "C:\Program Files (x86)\IIS Express"
IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:12345/ -UseSelfSigned
Make sure you run VS2017
As Administrator
and check if the issue addressed
Note: https://localhost:12345/
is what is in your launchSettings.json
for HTTPS
Solution 3
Changing port number has resolved the issue
Solution 4
Just Delete the (obj)Object folder in project folder then Run the application then It will work fine. Steps:
- Right Click on the project folder then select "Open folder in file Explorer".
- Then Find the Obj folder and Delete that.
- Run the Application.
Solution 5
Unfortunately, none of these answers worked for me. This answer finally did for Chrome only. Unfortunately, you have to do it each time:
- Open this in your browser: chrome://net-internals/#hsts
- Go to Delete domain security policies
- Enter "localhost"
- Restart browser
Related videos on Youtube
Comments
-
duke almost 2 years
I have copied my solution file from another system and tried to run it on my machine: For this, I have gone to the project folder and deleted the previous solution file and copied the new one.
Now, it started giving me error. connection refused etc. So, I got one solution from here: How to solve ERR_CONNECTION_REFUSED when trying to connect to localhost running IISExpress - Error 502 (Cannot debug from Visual Studio)?
According to it, I changed the port number from 1049 to 1052. It loaded and one of the pages gets loaded. But when I entered the desired login credentials then it redirected to the older port again, like this:
http://localhost:1049/Home/SearchFlight
and the error is:
This site can’t be reached localhost refused to connect. Search Google for localhost 1049 Home Search Flight ERR_CONNECTION_REFUSED
Now, I don't know what to do from here. I have changed the port number to 1052 but still its pointing to 1049. What should i do now?
-
WillC over 7 yearsThis worked for me. You may need to start VS in Administrator mode.
-
Baimyrza Shamyr over 7 yearsI am getting error "Unable to launch IIS Web server".
-
Nathan Tregillus over 6 yearstried this, still getting the "This site can't be reached" message. (I also tried to open in admin mode, didn't help)
-
Gags almost 6 yearsWorked for me as well
-
Diomos over 5 yearsthis actually helped. I had combined issue: Fiddler running and certificate missing.
-
jstuardo over 5 yearsThat is solved momentarily. I get bored changing the port every time I run the project.
-
Osify over 5 yearsWhen we copy whole project to another PC so the project also handle our own .vs config so delete that hidden folder, reopen the project in new PC, it will be working.
-
netchicken over 5 yearsUsing VS 2019 Preview 2. Got the same error, and fixed it by changing to the Project URL above. (goodness knows why) :-)
-
MusicAndCode about 5 yearsDidn't worked until restart of VS 2017. No need for Admin mode.
-
Christine about 5 yearsProcess with an Id of 27456 is not running.
-
moomoo about 5 yearsI'd wager that this is the case 90% of the time. Note that when you install a VS update and click "Launch" at the end of installation, it will NOT run as administrator. Gets me every time.
-
Dr. Hilarius about 5 yearsThis was the winner for me. I had added an openssl cert for a different app on a different port on localhost, and it hosed the self-signed cert I was using for iis express. Repairing the self-signed cert on the specific localhost port fixed it.
-
tagustini almost 5 yearsFixed, thank you so much! I've seen a lot of people saying delete .vs folder, but this is the first answer I've seen about the ssl cert, that was the clincher for me.
-
tdbeckett over 4 yearsthe file was in more than one place. In addition to this, I had to restart VS.
-
Vitaliy Markitanov over 4 yearsin my case i had to run on different port, on 44343. IisExpressAdminCmd.exe setupsslUrl -url:localhost:44343 -UseSelfSigned
-
William over 4 yearsI actually had to delete the whole .vs folder and change the port number, but at least eventually it worked
-
Quiver over 4 yearsAt one point in time I added a url reserveration for
http://*:44300/
and this is what was causing localhost to not connect for me. I ran a similar command as you,netsh http delete urlacl http://*:44300/
and localhost connects and debugs as expected now! -
Mahender Reddy Yasa almost 4 years@Kush I'm trying to debug react app with chrome extension and I don't see .vs folder even in hidden items but see .vscode folder which has launch.json, is this solution specific to only .net or react as well
-
Dmitresky over 3 yearsDeleting .vs folder didn't help me. But repair helped. Thanks a lot
-
Ben over 3 yearsAlso possible two instances of Visual Studio with different projects are running on the same port. Making the ports different worked for me.
-
oneberenjena over 3 yearsFantastic answer. In my case, I was trying to get the site to be remotely accessed using ngrok for that purpose. It didn't work for me and I left it unaccessible for that particular port, forgetting totally that during the proccess I eventually used
netsh http add
. Thank you very much! -
Nard Dog over 3 yearsWow, I've been trying to fix this issue with trying to debug in VSCode the last hour and a half, this finally did it.
-
useruser00 over 3 yearsMy application was working fine until recently, started getting "this site cant be reached" messages in browser.... this solved my issue
-
Will Strohl about 3 yearsI can't believe this was the fix for me. I've never run into this before. 🤷♂️
-
Amir Dora. about 3 yearsplease do not copy and paste the answers that are already there. If an answer helps you just upvote that answer.
-
E-A almost 3 yearsNone of the above and other sites solved my problem but this one did!
-
Ravi Ram over 2 yearsAfter 2 days, reading and trying all sorts of things, IISExpress Repair fixed it. I am able to run .Net Core 5 WebApp out of the box setup. Finally
-
loonix over 2 yearsMine worked with your and @SharpC answer combined
-
Dylan Karimagoko over 2 yearsThanks champ this actually worked thanks a lot
-
TMan over 2 yearsI got a popup window saying something about a problem in my localhost configuration when trying to run a web project locally. The error message pointed to a chrome process that was locking the port. I assume that rebooting the machine would have fixed the problem, but for me the issue was fixed by closing all instances of Chrome and trying again. Apparently one of them (although I could not find a visible window) was lurking in the background and blocking the port.
-
corix010 over 2 years@jstuardo interesting, mine was solved permanently. I don't have to change it every time.
-
Mohammadreza Askari over 2 yearsthis question tagged for iis, but your answer is solved my problem for me after trying a lot of useless things. thank you. to other know, this is for docker launcher.
-
Anthony rono almost 2 yearsthis one did it for me
-
Cheung almost 2 yearsThis is works, description on Docker's document - "publishAllPorts" : Allocates an ephemeral host port for all of a container’s exposed ports, it seems it conflict with specific port declare by ASP.NET core project.