How to solve ERR_CONNECTION_REFUSED when trying to connect to localhost running IISExpress - Error 502 (Cannot debug from Visual Studio)?

498,129

Solution 1

Try changing the port number in your project?

Project Properties → Web → Servers → Project Url:

enter image description here

Don't forget to click Create Virtual Directory, or reply "Yes" to the prompt for creating virtual directory after you change your port number! (Thanks Connor)

Note: I'm a little reluctant to post this as an answer, as I have no idea what the issue is or what caused it, but I had a similar issue, and changing the port number did the trick for me. I'm only posting this per the suggestion in the comments that this worked for someone else as well.

In my case, it seemed like something was conflicting with the specific port number I was using, so I changed to a different one, and my site popped right back up! I'm not sure what that means for the old port number, or if I'll ever be able to use it again. Maybe someone more knowledgeable than myself can chime in on this.

Solution 2

This issue may be because in the recent past you have used IP address binding in your application configuration.

Steps to Solve the issue:

  • Run below command in administrator access command terminal

netsh http show iplisten

If you see some thing like below then this solution may not help you.

IP addresses present in the IP listen to list:

0.0.0.0

If you see something different than 0.0.0.0 then try below steps to fix this.

  • Run following shell command in order with elevated command terminal

netsh http delete iplisten ipaddress=11.22.33.44

netsh http add iplisten ipaddress=0.0.0.0

iisreset

  • (Here 11.22.33.44 is the actual IP that needs to be removed)

And now your issexpress is set to listen to any ping coming to localhost binding.

Solution 3

Thanks for all the answers. I tried all of them but none of them worked for me. What did work was to delete the applicationhost.config from the .vs folder (found in the folder of your project/solution) and create a new virtual directory (Project Properties > Web > Create Virtual Directory). Hope this will help somebody else.

Solution 4

I've just fixed this for my machine. Maybe it will work for some. Maybe not for others, but here is what worked for me.

In IIS, I had to add bindings for https to the default website (or, I suppose, the website you are running the app under).

enter image description here

Now my localhost works when debugging from Visual Studio.

Solution 5

I had the same problem. I tried these steps:

  1. Closed the Visual Studio 2017
  2. Removed the [solutionPath].vs\config\applicationhost.config
  3. Reopened the solution and clicked on [Create Virtual Directory]
  4. Tried to run => ERR_CONNECTION_REFUSED
  5. FAILED

Another try:

  1. Closed the Visual Studio 2017
  2. Removed the [solutionPath].vs\config\applicationhost.config
  3. Removed the .\Documents\IISExpress\config\applicationhost.config
  4. Reopened the solution and clicked on [Create Virtual Directory]
  5. Tried to run => ERR_CONNECTION_REFUSED
  6. FAILED

Another try:

  1. Closed the Visual Studio 2017
  2. Removed the [solutionPath].vs\config\applicationhost.config
  3. Removed the .\Documents\IISExpress\config\applicationhost.config
  4. Added 127.0.0.1 localhost to C:\Windows\System32\drivers\etc\hosts
  5. Reopened the solution and clicked on [Create Virtual Directory]
  6. Tried to run => ERR_CONNECTION_REFUSED
  7. FAILED

WHAT IT WORKED:

  1. Close the Visual Studio 2017
  2. Remove the [solutionPath].vs\config\applicationhost.config
  3. Start "Manage computer certificates" and Locate certificate "localhost" in Personal-> Certificates enter image description here
  4. Remove that certificate (do this on your own risk)
  5. Start Control Panel\All Control Panel Items\Programs and Features
  6. Locate "IIS 10.0 Express" (or your own IIS Express version)
  7. Click on "Repair" enter image description here
  8. Reopen the solution and clicked on [Create Virtual Directory]
  9. Start the web-project.
  10. You will get this question:enter image description here. Click "Yes"
  11. You will get this Question: enter image description here. Click "Yes"
  12. Now it works.
Share:
498,129

Related videos on Youtube

ElHaix
Author by

ElHaix

Solutions architect in a drive for consistently learning and assisting when possible.

Updated on April 29, 2022

Comments

  • ElHaix
    ElHaix about 2 years

    This is running on Windows Server 2008 and used to work several months ago. I am just now using this server again for some dev work with VS.

    This is live web server used to serve up a few test sites as well.

    This came up when running Visual Studio, then launching my projects for debugging.

    Trying to launch any site through localhost:xxxx when IISExpress has been launched (using actual port #'s in the config to access different sites):

    This webpage is not available
    
    ERR_CONNECTION_REFUSED
    

    I have been at this for a few days already, as I have read others have had similar issues, tried most things I have read including changing the managedruntimeversion from "v4.0" to "v4.0.30319" for .net 4.5 (I have never had to do this before) and disabling the logging module (all suggestions found here).

    There are only two entries in my hosts file that point to internal server IP addresses. No localhost related IP's or references.

    I have gone as far as re-installing IIS Express, and Visual Studio 2013. I also created a brand new WebApplication site to try to resolve this (simple and no other complicated bindings).

    When I spin up Fiddler, I see the following on the page:

    [Fiddler] The socket connection to localhost failed. 
    ErrorCode: 10061. 
    No connection could be made because the target machine actively refused it 127.0.0.1:23162
    

    Fiddler capture

    I have removed all proxy settings from IE's LAN connection section, where before I was getting a red-x popup in VS indicating something like IISExpress could not launch.

    This is not a matter of SSL vs non SSL.

    I had TFS Server installed - uninstalled that in case there were some odd bindings that were interfering.

    I tried deleting the IISExpress config/settings folder several times.

    Current applicationhost.config contains:

    <site name="WebApplication1" id="4">
                    <application path="/" applicationPool="Clr4IntegratedAppPool">
                        <virtualDirectory path="/" physicalPath="C:\TFS-WorkRepository\Sandbox\WebApplication1\WebApplication1" />
                    </application>
                    <bindings>
                        <binding protocol="http" bindingInformation="*:23162:localhost" />
                    </bindings>
                </site>
                <siteDefaults>
                    <logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
                    <traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
                </siteDefaults>
                <applicationDefaults applicationPool="Clr4IntegratedAppPool" />
    

    I wish there was a tag for really-stuck.

    Please suggest away, as I don't want to go as far as spinning up a new server.

    -- UPDATE --

    In the URL bar, when I enter the computer name or IP address :xxxx I get the ERR_CONNECTION_TIMED_OUT rather than ERR_CONNECTION_REFUSED.

  • Don Cheadle
    Don Cheadle about 8 years
    this worked for me - rather than modifying browser settings as mentioned in this Answer stackoverflow.com/questions/7227845/…
  • GraehamF
    GraehamF almost 8 years
    this worked for me. after changing the port number, i was prompted to change my virtual directory, which had somehow changed to be incorrect.
  • Joseph Ferris
    Joseph Ferris over 7 years
    This worked for me, as well. No idea how it happened. I stopped IIS Express, and on next run, nothing but the error.
  • Starnetter
    Starnetter over 7 years
    I ran into the same problem when I opened a VS2015 solution in VS2013 and worked in it for a while and then went back to VS2015. Deleting the applicationhost.config solved it.
  • Stafford Williams
    Stafford Williams over 7 years
    This was the answer for me, although I don't remember running VS as administrator the first time I opened the project when it did work.
  • johntrepreneur
    johntrepreneur about 7 years
    oh yea duh (slaps forehead)
  • Parveen
    Parveen almost 7 years
    Thanks , solved my problem. After deleting reserved URL ,rebuild the project and then it work perfectly without Admin mode.
  • Connor Williams
    Connor Williams over 6 years
    Be sure to click 'Create Virtual Directory' after you change your port number!
  • sǝɯɐſ
    sǝɯɐſ over 6 years
    Just had this happen to me again today! :/ While I'm glad my suggestion is helping people, I sure wish I could figure out what is going wrong. Slowly going through usable port numbers over here :P
  • Abid Ali
    Abid Ali about 6 years
    This did not work for me. Changing my browser proxy settings to No Proxy solved this issue.
  • Alex
    Alex almost 5 years
    In my case applicationhost.config and restarting Visual Studio led to "project loading failed". I couldn't even access project properties then.
  • DubDub
    DubDub over 4 years
    Just to note, a check to see if this is the problem is simply changing https to http in your URL, as the http binding should already be in place.
  • Sethles
    Sethles over 4 years
    @Niraj Kumar Chauhan saved the day bud!! Lifesaver... Not sure how 0.0.0.0 got deleted in the first place but adding it back resolved the issue.
  • MattV
    MattV over 4 years
    After seven hours of searching for why Power BI Report Server was not listening properly: the 2 seconds of doing this fixed it. Thanks! Our existing config had '::' instead of 0.0.0.0; Is this not the same and/or how could this have been changed?
  • Shaakir
    Shaakir over 4 years
    This worked for me only after unticking "Override application root URL"
  • Mathew Alden
    Mathew Alden about 4 years
    Hey it worked! On my computer, the first command showed zero IP addresses, so I simply ran the "add" command and the "iisreset" command. After that, I still needed to redeploy my project and restart IIS a second time, but then it worked.
  • Mathew Alden
    Mathew Alden almost 4 years
    This fixed it for me. I suspect that when I told Visual Studio to build a second app to my dev IIS server, something must have deleted the bindings of my first app.
  • Slipoch
    Slipoch over 3 years
    best answer here,.
  • gawkface
    gawkface about 3 years
    I had to also remove a binding net.tcp 808:* that was there (I really dont know its significance so exercise caution) but for me these 2 things - adding https:443 (to existing http :80) and removing net.tcp eventually worked!! (after trying all the numerous whatnots grrr)