Solutions to Error "Unable to connect to Web Server IIS Express"
2021-08-04 10:00
Issue
IIS Express will occasionally not be able to start on a particular port with this error.
Unable to connect to Web Server IIS Express
In some cases, it's because another app is using that port. But often the reason is that Hyper-V has reserved one or more of the ports. To see which ports are currently excluded/reserved, run this command.
Note: all commands are in PowerShell 7 and should be run as Administrator
netsh int ipv4 show excludedportrange protocol=tcp
The result may look something like this.
Start Port End Port
---------- --------
50000 50059 *
54675 54774
54840 54939
54940 55039
55040 55139
55140 55239
55329 55428
55429 55528
As far as I can tell, Hyper-V doesn't have a known port range it will attempt to use and work around. So, the solution is to exclude the individual ports your projects require.
You can check which ports the apps use by looking at the launchSettings.json
files (assuming .NET Core). Be sure to include both the HTTP and SSL ports. Let's say, across all your projects, IIS Express will need to run on ports 44431,44435,54700,54701.
- Disable Hyper-V
dism.exe /Online /Disable-Feature:Microsoft-Hyper-V
- Restart when prompted
- Run this script, substituting your ports
$ports = 44431,44435,54700,54701 foreach ($port in $ports) { netsh int ipv4 add excludedportrange protocol=tcp startport=$port numberofports=1 }
- Reenable Hyper-V
dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All
- Restart when prompted
Troubleshooting
Error: The process cannot access the file because it is being used by another process.
If you get this error when running netsh
to exclude the port, the port is already excluded. It's a confusing error message.
Windows could not start the Hyper-V Virtual Machine Management service on Local Computer. Error 0x8007000e: Not enough memory resources are available to complete this operation.
If you attempt to start the Hyper-V Virtual Machine Management service and get this error, it can be caused if the Hyper-V Host Compute Service is Disabled. Open Services and set that service as Manual.
References
- Administered Port Exclusions blocking high ports – The 'almost not worth having' blog
- Unable to bind ports: Docker-for-Windows & Hyper-V excluding but not using important port ranges · Issue #3171 · docker/for-win
- What to Do When Hyper-V Won’t Start - vembu
- windows - Cannot bind to some ports due to permission denied - Stack Overflow
- How to use reserved port in netTcpBinding and basicHttpBinding in a WCF Application | Microsoft Docs
- windows 10, port reserved for HyperV
- The default dynamic port range for TCP/IP has changed in Windows Vista and in Windows Server 2008 - Windows Server | Microsoft Docs
- windows 10 - How to remove a Hyper-V virtual Ethernet switch - Super User
- Hyper-V Manager unable to connect to server "Local computer"
- Error: 0x8007000e Not enough memory resources are available to complete this operation. · Issue #5240 · microsoft/WSL
- Windows 10 Hyper-V System Requirements | Microsoft Docs
- windows - How do I find out why certain ports are excluded and delete the exclusion? - Server Fault
- hyper v - What is Administered port exclusions in windows 10? - Stack Overflow