108

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.

hbulens
  • 1,610
  • 3
  • 24
  • 40
ElHaix
  • 12,261
  • 24
  • 106
  • 193
  • [This fix all my problems on Opera and Chrome browsers](https://stackoverflow.com/questions/25277457/google-chrome-redirecting-localhost-to-https/28586593#28586593) – Murat Özbayraktar May 26 '20 at 08:48

22 Answers22

105

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.

sǝɯɐſ
  • 2,331
  • 3
  • 24
  • 44
  • 1
    this worked for me - rather than modifying browser settings as mentioned in this Answer http://stackoverflow.com/questions/7227845/localhost-not-working-in-chrome-and-firefox – Don Cheadle Apr 04 '16 at 16:00
  • this worked for me. after changing the port number, i was prompted to change my virtual directory, which had somehow changed to be incorrect. – GraehamF Jul 01 '16 at 02:15
  • This worked for me, as well. No idea how it happened. I stopped IIS Express, and on next run, nothing but the error. – Joseph Ferris Sep 19 '16 at 22:32
  • 1
    Be sure to click 'Create Virtual Directory' after you change your port number! – Connor Williams Aug 29 '17 at 16:03
  • 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 – sǝɯɐſ Oct 11 '17 at 14:26
  • This did not work for me. Changing my browser proxy settings to No Proxy solved this issue. – Abid Ali Apr 10 '18 at 06:50
  • This worked for me only after unticking "Override application root URL" – Shaakir Feb 13 '20 at 06:43
41

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.

Annie Lagang
  • 3,135
  • 1
  • 25
  • 36
  • 3
    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. – Gary.Ray Jan 27 '17 at 21:39
  • In my case applicationhost.config and restarting Visual Studio led to "project loading failed". I couldn't even access project properties then. – Alex May 30 '19 at 12:37
41

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.

  • @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. – Sethles Dec 11 '19 at 10:19
  • 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? – MattV Jan 27 '20 at 12:53
  • 1
    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 Apr 24 '20 at 16:35
  • best answer here,. – Slipoch Feb 01 '21 at 04:42
22

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.

Stuart
  • 1,446
  • 5
  • 24
  • 44
  • 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. – DubDub Oct 24 '19 at 15:02
  • 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. – Mathew Alden Jun 03 '20 at 00:00
  • 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) – gawkface Feb 23 '21 at 07:59
7

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.
Lucian
  • 3,118
  • 18
  • 18
6

Sam's solution worked for me, but I didn't want to run as admin as a permanent solution.

This is how I solved it in my case:

  1. Run CMD as admin
  2. Type "netsh http show urlacl" and find the reserved url with the relevant port
  3. Type "netsh http delete urlacl url=YourReservedUrlHere"

After that I could run my app without the need for admin rights. But it did messed with the ability to browse to my app from an external computer. Close enough for me for now.

RoyBS
  • 1,153
  • 14
  • 16
  • Thanks , solved my problem. After deleting reserved URL ,rebuild the project and then it work perfectly without Admin mode. – Parveen Jul 13 '17 at 06:39
5

In my case it was caused by starting IIS with no administrative rights. When I launched IIS as admin and started the site it worked fine

sam
  • 4,032
  • 4
  • 27
  • 34
3

In my case, it was caused by an infinite loop/stack overflow.

Josh
  • 1,646
  • 3
  • 20
  • 30
2

In my case, my co-worker changed the solution name so that after I get latest version of the project, I run my web application with IIS EXPRESS, then I got the message ERR_CONNECTION_REFUSED in my google chrome.

After I try all the solution that I find on the internet, finally I solved the problem with these steps :

  1. Close VS
  2. Delete the .vs folder in the project folder enter image description here

  3. Run As Administrator VS

  4. Open Debug > [Your Application] Properties > Web

  5. Change the port in Project URL and don't forget using https because in my case, when I'm using http it still did not work.

  6. Click Create virtual directory

  7. Run the application again using IIS EXPRESS.

  8. And the web application ran successfully.

Hope these helps.

Satria Janaka
  • 327
  • 2
  • 8
1

I solved this problem by starting Visual Studio with Run as administrator. This is also required if you want to publish your project to the local IIS.

To set this permanently:-

  1. Right-click on the Visual Studio icon
  2. Select Properties
  3. Click Advanced
  4. Ensure Run as administrator is checked-on
  5. Click on OK all the way out.
  6. Start Visual Studio, load your project and start debugging
joehanna
  • 1,396
  • 1
  • 9
  • 21
1

I've solved by going to Project Properties -> Debug, after enable SSL and use the address in your browser

enter image description here

Shiva
  • 18,435
  • 13
  • 75
  • 104
WiseTap
  • 3,383
  • 1
  • 16
  • 24
0

Rebuild All worked for me. VS2013, IIS Express.

JohnWrensby
  • 1,954
  • 1
  • 14
  • 17
0

Make sure you have a start page specified, as well. Right click on the .aspx page you want to use as your start page and choose "Set as start page"

Glade Mellor
  • 1,226
  • 16
  • 9
0

A simple work around(it worked for me) is use the IP address instead of localhost. This should be fine for your development tasks.

raj240
  • 448
  • 4
  • 12
0

I tried a lot of methods on Chrome but the only thing that worked for me was "Clear browsing data"

Had to do the "advanced" version because standard didn't work. I suspect it was "Content Settings" that was doing it.

GrowthCode
  • 55
  • 1
  • 7
0

I recently encounter this issue when I copy the source code from another machine.

-> Delete the .vs folder (it is hidden folder, so make sure you have enable view hidden folder option)
-> open visual studio and build your project. Visual studio will create new .vs folder as per current system configuration

Ubiquitous Developers
  • 3,161
  • 4
  • 25
  • 61
0

While probably not related to your problem, I had the same issue today. As it turns out, I had enabled an URL Rewrite module to force my site to use HTTPS instead of HTTP and on my production environment, this worked just fine. But on my development system, where it runs as an application within my default site, it failed...
As it turns out, my default site had no binding for HTTPS so the rewrite module would send me from HTTP to HTTPS, yet nothing was listening to the HTTPS port...
There's a chance that you have this issue for a similar reason. This error seems to occur if there's no proper binding for the site you're trying to access...

Wim ten Brink
  • 24,763
  • 19
  • 72
  • 138
0

This may be relevant to a certain subset of people with this issue...perhaps in a different flavor.

I was forcing an https redirect on RELEASE.

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
  filters.Add(new HandleErrorAttribute());
  #if !DEBUG
  filters.Add(new RequireHttpsAttribute());
  #endif    
}

And there wasn't https enabled on my iis express. Working correctly on DEBUG

Pinch
  • 3,586
  • 8
  • 31
  • 58
0

I was simply trying to Bind IP with IIS but ended up messing with IIS config files I literally tried 20+ solutions for this, which includes

  1. .vs file deletion of a project solution
  2. IIS folder config file deletion
  3. IIS folder deletion
  4. VS2019 Updation
  5. VS2019 repair
  6. Countless times machine and VS restart
  7. various commands on CMS
  8. various software updates
  9. Various ports change

but what worked which may work for someone else as well was to REPAIR IIS from

Control Panel\Programs\Programs and Features

Else you can refer to this answer as well

IIS10 Repair

Chameleon
  • 99
  • 1
  • 8
0

Ensure Script Debugging is disabled

enter image description here

I was getting this intermittently despite having tried several of the above suggestions. As soon as I disabled this, my debugging my site worked like a dream. (Think I'd only turned it on by accident, or perhaps in a previous life).

hnodrog
  • 33
  • 6
0

If you are using "real" IIS, this can occur if the W3SVC (World Wide Web Publishing) service is stopped.

Should seem obvious but if you accidentally stopped the service or have it set to manual this could happen to you.

I know the title says IIS express however google doesn't seem to filter out the express even when using a -Express hint so hopefully this helps someone else who found this page instead of an IIS-specific one.

Justin
  • 897
  • 10
  • 23
0

I initially tried everything here in this post so far EXCEPT for repairing IIS 10 Express and none of it worked for me. I didn't repair IIS 10 Express because when you install it via visual studio it wants to repair via Visual Studio and not via the programs and features.

I found if I go and repair visual studio, it wants to reset everything (e.g. your extensions and customizations) which seems like overkill.

If you try to uncheck IIS 10 Express from Visual Studio Features it threatens to remove all of the components related to it (e.g. ASP.NET). This also seemed like overkill.

In the end, I got it working by going to Tools -> Get Tools and Features (inside Visual Studio 2019), unchecking ASP.NET and web development AND THEN immediately rechecking it again, then clicking OK. This caused it to do a repair just on THOSE ASP.NET and web development components.

Note: I think I just took the defaults for the ASP.NET and web development workload so unchecking and rechecking might clear some components that are not there by default.

It didn't remove anything or reset the settings from what I can tell but I can now access my web api via localhost as expected.

Mike Cheel
  • 10,950
  • 8
  • 67
  • 96