Unable to connect to web server 'IIS Express'
Asked Answered
P

21

49

I am using Microsoft Visual Studio 2019 Community preview, version 16.4.0 Preview 1.0. I just updated to Windows 10 Pro Version 1903 OS build 18362.418. With an ASP.NET Core 3 web app project (Blazor Server), When I press F5, I catch an error.

I can go to https://localhost:44333/ manually, but it is inconvenient. When I stop debug, I also turn off it manually at taskbar.

With another web app project, the problem is not happen.

Whether I choose or do not choose the option "Enable native code debugging", no success.

How do I fix it?

Primogeniture answered 11/10, 2019 at 18:21 Comment(2)
Do you just want to attach to the process? Then possible duplicate of https://mcmap.net/q/94746/-asp-net-core-debug-attach-to-process-is-not-working (".. you will have to attach "dotnet.exe" process in Visual Studio")Univocal
Does this answer your question? Unable to launch the IIS Express Web serverHist
J
60

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/
Jesselyn answered 6/12, 2019 at 10:38 Comment(3)
Thanks, I recently upgraded to Win 10 Pro and that was when message "Unable to connect to web server 'IIS Express'" started to show. Running netsh http add iplisten ipaddress=0.0.0.0 solved it for me.Kell
$ netsh int ipv4 show dynamicport tcp, On my machine that's starting from port 49152. So make sure your project doesn't use ports above that number.Honeysweet
Updating my Applicationhost Config fixed the error for meFugazy
G
39

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

Girasol answered 10/5, 2020 at 6:29 Comment(9)
Restarting works but the problem is this error sometimes happen right after a restart. It's weird, for me it happens a lot in some solutions but not others.Sideward
tried a lot of these other solutions... only thing that worked was to close SLN, Delete the .vs folder, reopen solution.Coralloid
Closing the solution, ditching the .vs folder and recycling IIS Express did the trick for me.Hola
This has worked for me a couple different times nowFatherinlaw
@EvConrad, after revisting this and other threads multiple times and trying everything, your solution worked for me. I even kept the old applicaitonhost.config from the .vs folder to see what difference a freshly generated file might contain. The only difference was the encoding of the .config file (UTF8 vs UTF8 w/BOM) and some leading whitespace before the row with the <binding> tag I had problems with.Momus
The next day, the problem reappears. And now it does not help deleting the .vs folder.Momus
This always seem to be the case for me. A simple machine restart, after a lot of tweaks has been done and undone. I come here to meet this same answer to jump start my brain... lolDevoted
Actually, the so-called "ridiculous" solution is the only one that works for me.Consciencestricken
Restarting the solution worked for meIguanodon
C
23

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.

  1. Went to the properties of the project -> Debug Tab
  2. Changed the port number in the AppURL to x + 1, i.e. for my instance http://localhost:44348 => http://localhost:44349
  3. Closed the solution
  4. Deleted the applicationhost config
  5. Reopened solution.
  6. Changed the port number back to the original

Voila

Cygnus answered 7/4, 2020 at 4:14 Comment(0)
B
13

Removing .vs folder will solve this issue.

  1. Go to application location
  2. Remove .vs folder(hidden folder)
  3. Start project again!
Block answered 26/2, 2021 at 3:17 Comment(0)
M
10

Nothing worked for me (including deleting .vs, deleting obj and bin, cleaning the projects, restarting VS Studio, running netstat -ao | findstr <port number> to find out who is using my port and so on). Nothing.

Nothing except this:

  1. Open PowerShell as an administrator
  2. Run Get-Process -Id (Get-NetTCPConnection -LocalPort MY-PORT-NUMBER).OwningProcess (change port number to your port number)
  3. Finally, in my case, this showed that this process: service host: windows push notifications system service is using my port. Note the ID of this process and..
  4. Go to Task Manager (more details) > Processes > find the process by that ID and kill the child process (because this parent process itself can't be killed without the system becoming unusable)

That's it. It was windows push notifications system service in my case. Once I found it and killed it - everything is working without having to restart the whole computer or changing the port number.

Muniment answered 1/2, 2021 at 9:37 Comment(5)
Why not just change the port number instead of killing a child process which you don't know if it's important to the system or not.Gravitation
@Gravitation I could ask the same question the system that decided to steal my port after long time of using it and developing my web server app :)Muniment
The system is free to use any free port. It doesn't keep track of what ports all the apps were using in the past and makes a decision about not using them ever.Gravitation
I get it, however, this happened to me in the middle of working on a distributed system with a bunch of microservices and for someone, it can be easier to just kill/restart the push notifications service than changing the port numbers or restarting the PC in the middle of dev session.Muniment
@Gravitation - Maybe the system should check to make sure the port is not already in use... jsBulganin
N
9

I have had this problem occasionally in the past. I can often resolve the problem by:

  1. Click on show hidden icon area of task bar. You'll see an IIS Express icon.
  2. Select the icon and you should see your website listed. Drill down in that menu click "Stop site".

On other occasions I have had corporate security software interfere with Visual Studio/IIS Express operations. Usually you can get around the issue by running Visual Studio as Administrator. I've attempt explain to the security guys what an awful idea that is but usually they do not understand.

Finally, if you are running a Asp.Net Core application you can just give up on IIS Express. If you look next to the play button, there is a drop list that says "IIS Express". If you open the list you'll see your application's name there. Select that one. You'll be running using kestrel instead of IIS Express.

Niklaus answered 12/10, 2019 at 20:1 Comment(2)
Stop site worked for me. The only minor change to number 2 above is that you right click on the icon to see your site.Delve
Yeah, I think I could shorten it to "friends don't let friends use IIS Express"Niklaus
H
5

I had the same issue, I was able to solve it by changing the Port number.

  1. Right click on the project and select properties
  2. Go to the Debug section
  3. Under Web Server Settings change App URL port [just increase by one]
Hawken answered 12/10, 2019 at 21:4 Comment(2)
To shed some light why this may work is because this forces the regeneration of ".vs\PROJECTNAME\config\applicationhost.config".Sideward
you can use this to check for port availability as just incrementing by 1 might not work. netsh interface ipv4 show excludedportrange tcp and can delete them like this (sometimes) netsh interface ipv4 delete excludedportrange tcp 4990 100Lamarlamarck
B
5

I resolved this by closing Visual Studio (2019) and started it back up, running as Administrator.

Blancablanch answered 28/7, 2020 at 15:55 Comment(0)
D
2

All the above solutions did not work for me, however what worked was a simple fix after going through multiple solution;

Please follow the steps below;

  1. Go to your project/main solution folder in visual studio
  2. Right click on it and choose properties
  3. Go to the debug tab
  4. Scroll down to the Web Server Settings and turn off SSL

enter image description here

  1. Run your solution again, and you should be able to continue without errors
Dissentient answered 10/11, 2021 at 9:26 Comment(1)
In 2024 This is still the wayOutrelief
B
2

This works for me:

  1. Delete the "launchSettings.json" inside the "Properties" folder in the Project
  2. Open the project in Visual Studio
  3. Rebuild the project
  4. Debug (F5) or Run (Ctrl + F5).
Bealle answered 16/12, 2021 at 11:59 Comment(0)
B
1

For me I had another application using the same port, I changed the port in project debug settings to something else.

Bertolde answered 11/9, 2020 at 22:52 Comment(1)
In my experience, this is the answer 100% of the time. I don't know why a certain port gets bugged, but changing ports has always solved it for me.Kami
D
1

Changing the application url (by right clicking on the solution -> properties -> debug -> app url) from http://localhost:59017 to http://localhost:5901 (last number 7 deleted) worked for me. enter image description here

Dhu answered 28/1, 2021 at 7:57 Comment(0)
C
1

I had exactly the same problem with IIS Express that seemingly appeared out of nowhere. My solution was to simply open IIS Manager and restart IIS (in the right-side panel under Actions -> Manage Server). As a result, project start-up resumed working right away.

Conchiolin answered 17/4, 2021 at 16:43 Comment(0)
P
1

I was facing same issue, i tried all the way, i did not get proper solution. Finally i was resolved using below steps. In VS goto Tools=>Options=>Projects and solutions=>Web projects=> click checkbox -Use the 64 bit version of IIS express for website and projects.

With this i came out of my issue.

Pour answered 2/8, 2021 at 6:46 Comment(0)
P
1

Another thing to try if nothing works (or if you just want to get it working quick):

Uninstall IIS Express, and then re-install it - can be done from Visual Studio Installer components (Add/Remove).

Purlin answered 15/9, 2021 at 17:14 Comment(0)
A
0

Another option, and the one I prefer because one should not have to waste time fighting with IISExpress, is to run your project launch profile and not the IISExpress one.

Blazor is a .NET Core app so you can debug it with Kestrel.

Ataractic answered 15/5, 2020 at 12:12 Comment(6)
This breaks the auto-reload feature that you get with IIS Express and doesn't answer the OP's question.Rascality
@ChristopherHaws I'm not sure which technique for hot reloading Blazor you are talking about but running as a console app absolutely does not break that. Additionally, it is perfectly acceptable for answers to be helpful, they don't have to be "the" answer. Thanks for your opinion but but IIS Express is junk and I'm not going to use it, and I get by just fine without it.Ataractic
@ChristopherHaws I just did some research and trialing. IIS Express is worse than other reload solutions for Blazor because you can't use it while debugging.Ataractic
Not sure what you are talking about, I use IIS Express everyday for debugging. Also, I didn't say hot reload, that is a feature in the works from the ASP.NET team. At this point in time, there are two options for "automatically reloading when changes are made". 1) Use IIS Express (which automatically reloads when there are changes made to code while not debugging) or 2) Use dotnet run watch (which in .NET 5 gives a similar experience to the IIS Express one). As for using dotnet run (which is what this answer is talking about), this does not allow the site to reload automaticallyRascality
@ChristopherHaws its the best when people tell me what I already know. Thank you. My answer is helpful for people having this experience, it is an alternative. I knew all along it is not "the" answer but at least one person found it helpful enough to upvote so it adds value to the community. I can't count the times IISExpress has decided to lose its mind, why deal with it if you don't need to?Ataractic
The fix for something that is not working is not to use something else. The solution provided by @Cygnus actually fixes the issue raised by the OP's question.Rascality
C
0

I seem to have this annoying issue when there are more than one solution with the same name on the same workstation. The host file ends up having names app, app(1), app(2), app(N) and so on. The solution here is to manually adjust the host file to your likings in \app(N).vs\app\config\applicationhost.config to align with whatever port you set in Properties>Web>Project URL. You may also need to unload project and set the same port number in project config.

Christophany answered 12/9, 2021 at 1:5 Comment(0)
C
0

Rebooting my computer was the simplest "solution"

Consciencestricken answered 3/5, 2023 at 14:28 Comment(0)
H
0

Have you checked if you have any startup errors in your application itself?

In case of any technical misconfiguration during startup, it might be a viable solution to stop the application.

Hake answered 16/6, 2023 at 6:14 Comment(0)
T
0

In my case just needed to install missing .Net SDK version.

Try running app dotnet run in terminal, you'll get more info.

Tanny answered 20/11, 2023 at 13:34 Comment(0)
F
-1

I had the same issue. I was connected to my organization VPN. I simply disconnected the VPN, restarted IIS and tried again. It works fine now,

Frippery answered 8/3, 2021 at 5:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.