Why and how to fix? IIS Express "The specified port is in use"
Solution 1:
I had a similar issue running Visual Studio 2019 on Windows 10. Some solutions that worked for others seemed to include:
- Changing the application port number.
- Have Visual studio automatically assign a port number each time the application start.
- Restart Visual Studio
- Restart the computer.
Unfortunately, none of these solutions worked for me, assigning another port number did work but was not an acceptable solution as it was important for my application to run on a specified port.
The Solution
First I ran the command:
netsh http add iplisten ipaddress=::
from an elevated command-line process. This solved the initial error, when attempting to run the application I no longer got the "port in use" error, instead, I now got an error stating the application was unable to bind to the port because administrative privileges were required. (although I was running Visual Studio as administrator)
The second error was caused by Hyper-V that adds ports to the Port Exclusion Range, the port my application uses was in one of these exclusion ranges.
You can view these ports by running the following command: netsh interface ipv4 show excludedportrange protocol=tcp
To solve this second error:
- Disable Hyper-V: Control Panel-> Programs and Features-> Turn Windows features on or off. Untick Hyper-V
- Restart the computer.
- Add the port you are using to the port exclusion range:
netsh int ipv4 add excludedportrange protocol=tcp startport=50403 numberofports=1 store=persistent
- Reenable Hyper-V
- Restart the computer
From here everything worked perfectly.
Solution 2:
i solve the problem this way...
File -> Open -> Web Site...
After that select Local IIS under IIS Express Site remove the unwanted project.
hope this help.
Solution 3:
- change it in solution (right Click) -> property -> web tab
- Click Create Virtual Directory (in front of project Url textbox)
Solution 4:
This was haunting me for over a year!
For me,
- no website was running iin IIS Express
- nothing was using the port as determined by running:
netstat -ano
at the command line.
The solution was to run
netsh http add iplisten ipaddress=::
from the command line.
Happy days, and credit to: James Bryant! https://developercommunity.visualstudio.com/content/problem/110767/specified-port-is-in-use.html
Solution 5:
I had the same problem, but no proccess appeared neither in netstat nor in resmon.
What solved the problem for me was closing all the open browser windows.