10

saving work in progress

When trying to run a web-site from Visual Studio 2019 (or Visual Studio 2017, or Visual Studio 2015), i get the error:

  • Visual Studio 2015:

    enter image description here

    Unable to connect to the configured development Web server.

  • Visual Studio 2017:

    enter image description here

    Unable to connect to the configured development Web server.

    Output from IIS Express:
    Starting IIS Express...
    Successfully registered URL "http://localhost:59392/" for site "WebSite3" in application "/"
    Registration completed for site "WebSite3"
    IIS Express is running.

  • Visual Studio 2019:

    enter image description here

    Unable to connect to the configured development Web server.

    Output from IIS Express: Starting IIS Express ... Successfully registered URL "http://localhost:59392/" for site "WebSite3" application "/" Registration completed for site "WebSite3" IIS Express is running.

IISExpress is in fact running, and listening, but nothing actually works:

enter image description here

What have you tried - everything

Things i've tried (from every other question on Stackoverflow):

  • netsh http add urlacl url=http://localhost:56997/ user=everyone
  • run Visual Studio as an Administrator
  • restart Windows
  • delete the hidden .vs folder
  • run the web-site from a different folder
  • turn off the Windows Firewall
  • change the port of the web-site
  • change the port of the web-site and click Create Virtual Directory
  • delete the IISExpress folder from my Documents folder
  • install Visual Studio fresh (i installed 2019)

You can see IISExpress creating a listening socket, and IISExpress notification area icon shows that IISExpress considers the web-site running:

enter image description here

but it just won't respond to anything:

enter image description here

Bonus Chatter - Windows built-in kernel mode web server

IISExpress.exe does not open a listening socket itself.

Windows comes with a built-in kernel-mode mini webserver: http.sys. You, and IISExpress.exe, use this web web-server by calling:

//Initialize HTTP Server APIs
HttpInitialize(HTTPAPI_VERSION_1_0, HTTP_INITIALIZE_SERVER, null);

//Create a Request Queue
HANDLE requestQueue;
HttpCreateHttpHandle(ref requestQueue, 0);

/*
   Add URIs to listen on. We call HttpAddUrl for each URI.
   The URI is a fully qualified URI and must include the terminating (/) character.

   The IANA port numbers state ports 49152-65535 are for dynamic/private purposes.
   HttpAddUrl for localhost on a port >= 49152 works fine for non-admins.
*/
String url = "http://localhost:80/"; //Ports 1-1024 require administrator access

/*
   You can use netsh to modify the HttpServer api ACL to grant everyone acces s to port 80:

      netsh http add urlacl url=http://localhost:80/ user=EVERYONE listen=yes delegate=no

   But it is useful to note that WCF already has an "Everyone Allow" entry for port 80,
   as long as your URL starts with "/Temporary_Listen_Addresses/"

   WCF creates URLs of the form:

      http://+80/Temporary_Listen_Address/[random guid]/
*/
url = "http://+:80/Temporary_Listen_Addresses/{87CB7BDF-A52D-4496-AA1D-B6F60AC2841E}/"; //WCF style url

//Or we can just use one above 1024
url = "http://localhost:2113/";

Add the URL to your request queue

//Add the url to our request queue    
ret = HttpAddUrl(requestQueue, url, null);

And then you setup a loop to process the requests:

while (true)
{
   THTTP_REQUEST_ID requestID;
   Int32 requestBufferLength = sizeof(THTTP_REQUEST) + 16384;
   PHTTP_REQUEST request = GetMemory(requestBufferLength );
   DWORD bytesRead;

   ULONG res = HttpReceiveHttpRequest(requestQueue, 
                requestId,          // Req ID
                0,                  // Flags
                request,            // HTTP request buffer
                requestBufferLength,// req buffer length
                ref bytesRead,      // bytes received
                null                // LPOVERLAPPED
                );
   if (res == NO_ERROR)
   {
      res = SendHttpResponse(requestQueue, request, 451, "Totally not NSL", "I don't know what you mean ;)");
      if (res <> NO_ERROR) 
         break;

      // Reset the Request ID to handle the next request.
      requestID = 0;
   }
   else if (res == ERROR_MORE_DATA)
   {
      /*
         The input buffer was too small to hold the request headers.
         Increase the buffer size and call the API again.

         When calling the API again, handle the request that failed by passing a RequestID.
         This RequestID is read from the old buffer.
      */
      requestId = request.RequestId;

      //Free the old buffer and allocate a new buffer.
      requestBufferLength  = bytesRead;
      FreeMem(request);
      request = GetMemory(requestBufferLength);
   }
   else if ((result == ERROR_CONNECTION_INVALID) and (requestID <> 0)) 
   {
      /*
            The TCP connection was corrupted by the peer when attempting to handle a request with more buffer.
            Continue to the next request.
      */
      //Got invalid connection error
      requestID := 0;
   }
   else
   {
      // Other unhandled error; stopping processing requests
      break;
   }      
}

This is all by of way of explaining why it is System that is listening, and not IISExpress.exe.

And if you read the comments, you'll notice why trying to perform netsh http add urlacl is mostly cargo-cult programming; you don't need to add permissions for ports over 1024.

Related Questions

Ian Boyd
  • 220,884
  • 228
  • 805
  • 1,125
  • 5
    Me reading this: Finally, someone's asked the question with all the appropriate info, I'll just scroll down and see what the actual solution is... damn. If you had any luck solving this I'd love to know what it was? – DannyT Sep 28 '19 at 23:27

5 Answers5

1

In my case, I stop the firewall in nod32 smart scurity and problem solved!

Rooz
  • 189
  • 7
1

Go the application properties --> debug --> app URL check the port and change the port and remove the tick mark in the Enable SSL . This works for me Hope it will help you all

0

I tried absolutely everything listed above and in the end it was the Windows Firewall that was the culprit.

Opened firewall settings. Turned off both Private and Public Firewall. Restarted Visual Studio. Build. Run. Works.

Then turn the firewall back on again, step by step.

Karlth
  • 3,156
  • 2
  • 23
  • 28
0

I had faced same issue.But it got solved when I just switched from IIS express to Local IIS(the one with project name) and back to IIS express

0

I had the same problem from installing docker on a windows 10 machine. As a side effect, the hyper-v was activated, and a range of ports were not available anymore. See more on https://blog.sixthimpulse.com/2019/01/docker-for-windows-port-reservations/

My solution was to open up "windows and features" and disable hyper-v

enter image description here

Obviously, if you need hyper-v to be running, you can also view the list of ip ranges being reserved with this command: netsh int ipv4 show excludedportrange protocol=tcp and simply configure your project to use an IP address that is not reserved.

suisgrand
  • 100
  • 1
  • 5