ASP.NET 5 MVC: unable to connect to web server 'IIS Express'

后端 未结 30 1749
北恋
北恋 2020-12-12 13:28

What I\'m doing:

  • Opening Visual Studio Community 2015
  • File -> New -> Project
  • Under Visual C#: Web -> ASP.NET Web Application
  • Web App
相关标签:
30条回答
  • 2020-12-12 13:58

    I added .UseUrls("https://localhost:<some port>/") to the Program.cs. This seemed to do the trick for me!

    0 讨论(0)
  • 2020-12-12 13:58

    For me, IIS Express was not accessible when I added iplisten on DOS Prompt like this: netsh http add iplisten MyIPAddress. I fixed it by deleting the iplisten like this: netsh http delete iplisten MyIPAddress.

    0 讨论(0)
  • 2020-12-12 14:00

    Many of these answered don't fully address the issue at hand. The real problem for me was that I had two bindings using the same port in my applicationhost.config file AND I hadn't opened up the port to my second (non localhost) binding. VS will allow you to still run under these circumstances but only if you are in admin mode (hence all of the answers above).

    You are essentially creating two IIS express instances of your app on the same port, so changing one of the ports in your applicationhost.config file will allow you to proceed. There are two different applicationhost.config files however. You will want to select the one that has the binding IP and port that you see in your project's properties

    .

    Go to the folder where you can see your project solution and project folders (show hidden items in File Explorer). Navigate into your hidden .vs folder -> "YourAppName" folder -> config. It should contain the binding info you saw in your project's properties.

    Example:

    <bindings>
        <binding protocol="http" bindingInformation="*:7000:127.0.0.1" />
        <binding protocol="http" bindingInformation="*:7000:192.168.0.5" />
    </bindings>
    

    Change one of those port numbers to something other than "7000" so that you aren't trying to use the same port.

    In my case, I'm using a 192 address which is not a localhost address, so I need to use some netsh commands to open that port and ip up. Here is a Link that shows how to open up ports for IIS Express to allow remote connection. Running as a normal user will not work unless you run those netsh commands listed.

    Here are the netsh commands:

    1. netsh http add urlacl url=http://192.168.1.42:58938/ user=everyone
    2. netsh advfirewall firewall add rule name="IISExpressWeb" dir=in protocol=tcp localport=58938 profile=private remoteip=localsubnet action=allow

    Copy those commands and run them in cmd with ADMIN privileges and with YOUR ip address and port number.

    0 讨论(0)
  • 2020-12-12 14:00

    I had this same issue, but the way I fixed it was by going to the applicationhost.config and remove a port which was not added by me (IIS Express I would guess) which placed my specific port site on another port.

    Here is what the config file had for my bindings:

    <bindings>
          <binding protocol="http" bindingInformation="*:54764:localhost" />
          <binding protocol="https" bindingInformation="*:44360:localhost" />
    </bindings>
    

    I removed the first bindings item as the only port I wanted was 44360. My config file now looks like this:

    <bindings>
          <binding protocol="https" bindingInformation="*:44360:localhost" />
    </bindings>
    

    Now I don't see the error when I debug.

    I also noticed my second API in my project had port 80 also assigned to it, I removed that as well.

    0 讨论(0)
  • 2020-12-12 14:01

    Exit VS and delete the (project)\.vs\applicationhost.config file. Restart VS. It should start working.

    0 讨论(0)
  • 2020-12-12 14:03

    I was able to resolve this by restarting my computer. I tried a few things unsuccessfully and finally gave up and restarted my computer. It has been working well now for a couple of days after I restarted. Probably the result of some process that was hung.

    0 讨论(0)
提交回复
热议问题