Unable to connect to web server 'IIS Express'

51,038

Solution 1

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/

Solution 2

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

Solution 3

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

Solution 4

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.

Solution 5

Removing .vs folder will solve this issue.

  1. Go to application location
  2. Remove .vs folder(hidden folder)
  3. Start project again!
Share:
51,038
James Grey
Author by

James Grey

Updated on December 17, 2021

Comments

  • James Grey
    James Grey over 2 years

    I am using Microsoft Visual Studio 2019 Community preview, version 16.4.0 Preview 1.0. I just update to Windows 10 Pro Version 1903 OS build 18362.418 . With ASP.NET Core 3 web-app project (Blazor Server), When I press F5, I catch 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.

    When I choose or not choose option Enable native code debugging, not success.

    How to fix it?

  • Tomáš
    Tomáš about 4 years
    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.
  • Trinidad
    Trinidad almost 4 years
    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.
  • Trinidad
    Trinidad almost 4 years
    To shed some light why this may work is because this forces the regeneration of ".vs\PROJECTNAME\config\applicationhost.config".
  • Craig
    Craig over 3 years
    tried a lot of these other solutions... only thing that worked was to close SLN, Delete the .vs folder, reopen solution.
  • Christopher Haws
    Christopher Haws over 3 years
    This breaks the auto-reload feature that you get with IIS Express and doesn't answer the OP's question.
  • Crowcoder
    Crowcoder over 3 years
    @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.
  • Crowcoder
    Crowcoder over 3 years
    @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.
  • Mifo
    Mifo over 3 years
    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.
  • Christopher Haws
    Christopher Haws over 3 years
    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 automatically
  • Crowcoder
    Crowcoder over 3 years
    @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?
  • Christopher Haws
    Christopher Haws over 3 years
    The fix for something that is not working is not to use something else. The solution provided by @broguyman actually fixes the issue raised by the OP's question.
  • Ev Conrad
    Ev Conrad over 3 years
    Closing the solution, ditching the .vs folder and recycling IIS Express did the trick for me.
  • C.Ikongo
    C.Ikongo over 3 years
    Spent 5 hours on this, that one line did it for me netsh http add iplisten ipaddress=0.0.0.0. Thank you
  • LucidObscurity
    LucidObscurity about 3 years
    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 100
  • Karel Křesťan
    Karel Křesťan about 3 years
    Toggling SSL off fixed it for me. Thanks!
  • Jeremy Lakeman
    Jeremy Lakeman about 3 years
    $ 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.
  • Bennyboy1973
    Bennyboy1973 about 3 years
    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.
  • SuperJMN
    SuperJMN about 3 years
    Cycling the "enable SSL" worked for me. Thanks!
  • ActualRandy
    ActualRandy about 3 years
    This has worked for me a couple different times now
  • Dan Gøran Lunde
    Dan Gøran Lunde almost 2 years
    @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.
  • Dan Gøran Lunde
    Dan Gøran Lunde almost 2 years
    The next day, the problem reappears. And now it does not help deleting the .vs folder.