localhost refused to connect Error in visual studi

2019-01-14 11:14发布

问题:

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?

回答1:

I had a similar issue. Try this and it should work

  1. Go to your project folder and open .vs folder (keep your check hidden item-box checked as this folder may be hidden sometimes)

  2. in .vs folder - open config

  3. see that applicationhost config file there? Delete that thing.(Do not worry it will regenerate automatically once you recompile the project.)



回答2:

Changing port number has resolved the issue



回答3:

Just Delete the (obj)Object folder in project folder then Run the application then It will work fine. Steps:

  1. Right Click on the project folder then select "Open folder in file Explorer".
  2. Then Find the Obj folder and Delete that.
  3. Run the Application.


回答4:

I had the same problem. Deleting .vs folder (including all contents, folder might be hidden) worked for me.



回答5:

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: 

  1. Delete .vs folder (requires to close Visual Studio 2017)
  2. Run these commands in cmd:

    cd C:\Program Files (x86)\IIS Express

    IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:12345/ -UseSelfSigned

  3. 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



回答6:

I solved a similar problem by listing bound IP addresses in a cmd window running as admin:

netsh http show iplisten

Then, one by one, blowing them all away:

netsh http delete iplisten ipaddress=127.0.0.200
netsh http delete iplisten ipaddress=127.0.0.2
...


回答7:

I was having this issue and solved it by closing all open instances of Visual Studio.



回答8:

Unfortunately, none of these answers worked for me. This answer finally did for Chrome only. Unfortunately, you have to do it each time:

  1. Open this in your browser: chrome://net-internals/#hsts
  2. Go to Delete domain security policies
  3. Enter "localhost"
  4. Restart browser

Google Chrome redirecting localhost to https



回答9:

For this to work for me, all I had to do was recreate the virtual directory. I had re-installed Windows and then pulled the project back out of Git. To do this, right-click on the solution project and choose Properties, then go to the Web tab and click the Create Virtual Directory beside the Project Url.

I hope this helps someone else too!

Bud



回答10:

Project properties> Web > Create Virtual Directory worked for me



回答11:

Right Click on Project >> Properties >> Select Web Tab >> Under server Select "Use Visual development server" so indirectly it will uncheck "Local IIS Server"

Hope so it may resolve this issue.



回答12:

Open cmd as administrator and run this command:

netsh http delete iplisten ipaddress=xxx.xxx.x.xxx

ipaddress is your private ip.
This worked for me.



回答13:

This happened to me in VS2017 v 15.6.7 using .net core 2.0.

When the project first launched it created an SSL Cert for localhost and started fine. When I disabled SSL I kept getting this issue.

Apparently when you disable SSL the port numbers are changed and not all of the port numbers get changed to the new port. Make sure port numbers on Debug are all the same number.



回答14:

Like Donny V. this happened to me in VS2017 using .net core 2.0.

When the project first launched, VS displayed a dialog, offering to create an SSL Cert for localhost - but I didn't want to use SSL, so I stopped running and went into Project Properties and disabled SSL (a checkbox that can be cleared). After doing that I kept getting the issue described.

After trying many things what actually resolved the issue for me was editing the launchSettings.json file located under [ProjectName]/Properties - it's accessible from Solution Explorer.

When the editing was complete, the contents looked like this (where 12345 is a Port Number, and where MyNETCoreApp is the name of the project).

{
    "iisSettings": {
        "windowsAuthentication": false,
        "anonymousAuthentication": true,
        "iisExpress": {
            "applicationUrl": "http://localhost:12345/"
        }
    },
    "profiles": {
        "IIS Express": {
            "commandName": "IISExpress",
            "launchBrowser": true,
            "launchUrl": "http://localhost:12345/",
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            }
        },
        "MyNETCoreApp": {
            "commandName": "Project",
            "launchBrowser": true,
            "environmentVariables": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "applicationUrl": "http://localhost:12345/"
        }
    }
}

The edits I made were:

  • Updated the Port Numbers so they were all the same number
  • Removed a key:value of ssl:0 in one spot
  • Updated all https:// instances to be http://


回答15:

Change the port number and remove script debugging (if enabled) to resolve in localhost.



回答16:

I had to add https bindings in my local IIS



回答17:

This solution worked for me:

  1. Go to your project folder and open .vs folder (keep your check hidden item-box checked as this folder may be hidden sometimes)

  2. in .vs folder - open config

  3. see that applicationhost config file there? Delete that thing.(Do not worry it will regenerate automatically once you recompile the project.)



回答18:

I've tried everything but nothing worked, but this did. If you can debug on local IIS instead of Express, change the configurations as shown in the image below. Do not forget to click on "Create virtual directory"



回答19:

rebooting the machine was the only thing that worked for me



回答20:

I ran my Visual Studio as "Run as administrator" and this solved my problem.



回答21:

I recently ran into this exact problem and tried most of the suggestions but it turns out my problem was something different.

Our application has a section that redirects you to HTTPS if you are on HTTP (yes, I know there are better ways but this is legacy). In addition, there is special handling of localhost when you are in dev mode which redirected you back to HTTP, though I don't know why.

I have a new requirement that requires testing in HTTPS.

On a normal web page, changing http:// to https:// and calling Redirect would work fine but in IISExpress you are using custom ports. So for example, if you are on https://localhost:44300 you can't just switch to http://localhost:44300 b/c that port only serves https, not http.

So, if you are having this problem and you've cleared the config files and it didn't help, check your code for redirects. you might have something using a hardcoded or partially hardcoded url or a url from a config file that you haven't updated to https.

Update: I also suggest clearing all .suo and .user files and someone else suggested clearing the obj/ folder. I suggest doing this with VS closed and then restarting. I had a lot of trouble with values for ports being cached when i tried to setup https:// and change ports. I also suggest trying this suggestion to check that the SSL port is within the correct range, though I don't know if that is still a requirement https://stackoverflow.com/a/24957146