28

I clicked on create virtual directory of the web tab of the properties menu. My application now isn't running (the published version is) It just hangs when any of my controllers code is executed I think I've messed up the IIS config Can anyone help me out?

John
  • 329
  • 1
  • 6
  • 10

7 Answers7

34

enter image description here

My file was located here:

C:\Users\YourUserName\Documents\IISExpress\config\applicationhost.config

Entries will look like this

<application path="/virtualDirectoryName" applicationPool="Clr4IntegratedAppPool">
                    <virtualDirectory path="/" physicalPath="C:\projects\Project1" />
                </application>
BraveNewMath
  • 8,090
  • 5
  • 46
  • 51
27

None of this worked for me - possibly because I'm working with a later version of the tools (VS 2017). I finally found the correct appplicationhost.config file in the .vs directory for the solution, edited it, rebooted, and it worked.

Chris B. Behrens
  • 6,255
  • 8
  • 45
  • 71
14

If you created another virtual directory by mistake, go to your .vs folder inside your solution/project folder and look for a file called:

applicationhost.config
and change/fix what is inside the tag:
<sites>
   <site name="YourSite" id="1">
      ...
   </site>
   ...
</sites>

Hope this helps! :D

Diego Murakami
  • 191
  • 1
  • 6
8

I realize this has been answered a few times over, but had this exact same issue in VS 2019 so I performed the following steps:

  • Closed the Solution
  • Navigated in the file system to the .vs folder within my solution and deleted it
  • Reopened Solution and rebuilt.

Upon reopening the solution and Starting the project, it appeared to have worked without any sort of reboot.

Some may consider deleting the .vs folder destructive in some way but given the fact it's normally excluded from most (if not all source control systems) there isn't really anything mission critical in there and it all gets rebuilt anyways.

vandsh
  • 1,329
  • 15
  • 12
  • 1
    This just saved me after about an hour of frustration when IIS Express just suddenly decided to start serving old versions of my app during debugging, thanks! – Stephen Byrne Mar 29 '20 at 10:29
  • this helped a little but in the end i just cloned a fresh repo. All of the meta files that were corrupted just recreated fresh this way – cah1r Apr 25 '22 at 11:39
4

I faced the same issue today. The simplest way to deal with this is just simply change the Port number. Go to the Properties of the Project which you have made as Startup Project. Then...

Click to view => Step 1

Let's say the initial port number is 62168. Just increment it by 1.

Click to view => Step 2

And create a new virtual directory. Now execute the project again. This time it'll work.

Steps:

Go to Properties window of the project selected as the StartUp Project

Select the "Web" section present in the LHS of the Properties window

Go to the Servers part (which is present below the "Start Action" part )

In the Project URL section, increment the value of Port Number by 1 or 2 (modified Port number must be free) and click on "Create Virtual Directory"

Save the changes and run the application using CTRL+F5

Hope this helps!

3

You can use appcmd.exe in C:\program files (x86)\IISExpress

appcmd list vdir should list the virtual directories and appcmd delete vdir VDIR.NAME to delete. Or, if you use Powershell, the commands start with .\, e.g., .\appcmd list vdir.

Lam Le
  • 1,489
  • 3
  • 14
  • 31
VJKarl
  • 39
  • 3
1

VS 2019 -

There are multiple places that the applicationhost.config resides. Two of those should are where the virtual directory data is put.

First location:

C:\Users\YourUserName\Documents\IISExpress\config\applicationhost.config

Second location:

C:\YourPathToSolutionFolder\.vs\SolutionName\config\applicationhost.config.

** please note: in the .vs there are two folders one is the config folder and the other should be the name of your solution. Navigate into your solution named folder and you will find another config folder. Inside there is the applicationhost.config file you need to edit.

In both files you will need to remove the following (I just search for virtualdirectory).

<application path="/virtualDirectoryName" applicationPool="Clr4IntegratedAppPool">
    <virtualDirectory path="/" physicalPath="C:\projects\Project1" />
</application>

Hopefully you won't have to delete the entire .vs folder which is an option if needed.

Note: This combines two answer from above Diego Murakami and BraveNewMath

ZombieCode
  • 1,646
  • 2
  • 24
  • 46
  • The second location was `C:\YourPathToSolutionFolder\.vs\SolutionName\config\applicationhost.config` for me. @ZombieCode, can you check if you missed the `config` part of the path? – GreenRaccoon23 Jul 27 '22 at 14:55
  • 1
    You are correct. Thank you for catching that. I have fixed the post. – ZombieCode Aug 03 '22 at 07:02