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:
Unable to connect to the configured development Web server.
Visual Studio 2017:
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:
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:
Things i've tried (from every other question on Stackoverflow):
netsh http add urlacl url=http://localhost:56997/ user=everyone
.vs
folderYou can see IISExpress creating a listening socket, and IISExpress notification area icon shows that IISExpress considers the web-site running:
but it just won't respond to anything:
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.
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.
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
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
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.
Delete the .sln
file. Then Open the project as a Website and Save it. It will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With