"Unable to connect to web server 'IIS Express'"
I had the very same issue what OP described, I mean I got the error message, but checking the IIS Express icon, it was shown everything is OK, so manually going to the url was working.
Tried literally everything what is described above including
- Stop the site within IIS Express
- Stop IIS Express
- Exit VS restart VS
- Check everything in the .vs folder
- Delete the .vs folder
- as a POC created a brand new ASP.NET Core project, that worked properly
Nothing helped.
I know it is ridiculous as "solution", but after spending a half hour with this I finally restarted my machine and everything is working since then... Worth a try
Enable/disable SSL
This is the easy fix. For me, toggling the "Enable SSL" setting in the project Debug tab inside Visual Studio (just change it to the opposite of what is currently set and run the project) has fixed the issue.
As I understand it, there are two reason this might work. First it causes Visual Studio to update the Applicationhost Config (more about that later). Secondly, sometimes the SSL address is bound. Therefore disabling SSL disables the problem.
Applicationhost Config
Open your $(solutionDir)\.vs\config\applicationhost.config
file and ensure your site looks like this:
<site name="[YOUR PROJECT NAME]" id="3">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="//PATH/TO/YOUR PROJECT" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:[YOUR_PORT]:localhost" />
<binding protocol="https" bindingInformation="*:[YOUR_SSL_PORT]:localhost" />
</bindings>
</site>
Make sure iplisten is configured to 0.0.0.0
If the IP listen list is not configured, this issue may occur (caution, I have no idea why).
Check netsh to ensure there is an entry for 0.0.0.0
PS C:\Windows\system32> netsh http show iplisten
IP addresses present in the IP listen list:
-------------------------------------------
::
0.0.0.0
PS C:\Windows\system32>
Add the correct netsh rule if it does not exists. You'll need an admin cmd.exe or admin PowerShell for this.
PS C:\Windows\system32> netsh http add iplisten ipaddress=0.0.0.0
Ensure nothing is binding to the address you are using
This seems to be an issue with Blazor for me. If an address is binded to the address Blazor is trying to use, this can cause issues. Use netsh
again to check what is in use.
netsh http show urlacl
An entry that looks like this
Reserved URL : http://*:50902/
User: \Everyone
Listen: Yes
Delegate: No
SDDL: D:(A;;GX;;;WD)
Can be deleted with this command
netsh http del urlacl url=http://*:50902/
Thought I would throw in what worked for me even though I'm late to the party. The solutions above didn't work for me.
- Went to the properties of the project -> Debug Tab
- Changed the port number in the AppURL to x + 1, i.e. for my instance http://localhost:44348 => http://localhost:44349
- Closed the solution
- Deleted the applicationhost config
- Reopened solution.
- Changed the port number back to the original
Voila