Visual Studio 2015 - Adding virtual directory not possible

25,214

Solution 1

FileSystem Web site to IIS Express.

  1. Open VS2015 (Right click and select Run as administrator).
  2. Click File > New > Web Site...
  3. In the New Web Site dialog, click Browse... button.
  4. Select Local IIS in the left pane. And select IIS Express Sites in the right pane.
  5. There are 4 buttons in right side on top. Click Create New Site button.
  6. Give name and click Open.This will select HTTP in Web location.
  7. Click OK.
  8. Then close the solution.
  9. Open applicationhost.config from Users\\Documents\IISExpress\config folder. You can open in the notepad.
  10. Find your web site in sites section. And change the physical path inside (virtualDirectory path="/" physicalPath="C:\WebApp\WebSite1"). Write the path of your existing Web Project.
  11. Save and close applicationhost.config file.
  12. Run VS2015 (Run as administrator).
  13. Click File > Open > Web Site...
  14. In the Open Web Site dialog, select Local IIS from left pane.
  15. Select your site under IIS Express Sites and click Open.
  16. Click Web Site menu and New Virtual Directory...
  17. Give Alias Name and Folder path and click OK.

Now you can create it without error.

Solution 2

Neither of the answers above worked for me, I am still not sure why this works but here is what I did:

Modify the Applicationhost.config file that resides in the project:

Originally it looked like this:

<site name="Website" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\...\MyWebsite" />
    </application>

    <bindings>
        <binding protocol="http" bindingInformation="*:51005:localhost" />
    </bindings>
</site>

I had to add another application path entry:

<application path="/mywebsite" applicationPool="Clr4IntegratedAppPool">
    <virtualDirectory path="/" physicalPath="C:\...\MyWebsite" />
</application>

So it ends up looking like this:

<site name="Website" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\...\MyWebsite" />
    </application>

    <application path="/mywebsite" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\...\MyWebsite" />
    </application>

    <bindings>
        <binding protocol="http" bindingInformation="*:51005:localhost" />
    </bindings>
</site>

Solution 3

Alternative if you have solution file ".sln", then follow the steps:

  1. Use notepad open the solution file.

  2. Find the row starts with Project("{

For example:

Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "WebProject1", "WebProject1", ......

Then change it to be:

Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "WebProject1", "http://localhost:12345/WebProject1", ......

And add new property

SlnRelativePath = "C:\WebProject1\"

within ProjectSection(WebsiteProperties)

In example, the ProjectSection from

Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "WebProject1", "WebProject1", "{6D411253-734E-401A-A049-9620FC55D4FB}"
    ProjectSection(WebsiteProperties) = preProject
        UseIISExpress = "true"
        TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.0"
        Debug.AspNetCompiler.VirtualPath = "/WebProject1"
        Debug.AspNetCompiler.PhysicalPath = "C:\WebProject1\"
        Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\WebProject1\"
        Debug.AspNetCompiler.Updateable = "true"
        Debug.AspNetCompiler.ForceOverwrite = "true"
        Debug.AspNetCompiler.FixedNames = "false"
        Debug.AspNetCompiler.Debug = "True"
        Release.AspNetCompiler.VirtualPath = "/WebProject1"
        Release.AspNetCompiler.PhysicalPath = "C:\WebProject1\"
        Release.AspNetCompiler.TargetPath = "PrecompiledWeb\WebProject1\"
        Release.AspNetCompiler.Updateable = "true"
        Release.AspNetCompiler.ForceOverwrite = "true"
        Release.AspNetCompiler.FixedNames = "false"
        Release.AspNetCompiler.Debug = "False"
    EndProjectSection
EndProject

become this finally:

Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "WebProject1", "http://localhost:12345/WebProject1", "{6D411253-734E-401A-A049-9620FC55D4FB}"
    ProjectSection(WebsiteProperties) = preProject
        UseIISExpress = "true"
        TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.0"
        Debug.AspNetCompiler.VirtualPath = "/WebProject1"
        Debug.AspNetCompiler.PhysicalPath = "C:\WebProject1\"
        Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\WebProject1\"
        Debug.AspNetCompiler.Updateable = "true"
        Debug.AspNetCompiler.ForceOverwrite = "true"
        Debug.AspNetCompiler.FixedNames = "false"
        Debug.AspNetCompiler.Debug = "True"
        Release.AspNetCompiler.VirtualPath = "/WebProject1"
        Release.AspNetCompiler.PhysicalPath = "C:\WebProject1\"
        Release.AspNetCompiler.TargetPath = "PrecompiledWeb\WebProject1\"
        Release.AspNetCompiler.Updateable = "true"
        Release.AspNetCompiler.ForceOverwrite = "true"
        Release.AspNetCompiler.FixedNames = "false"
        Release.AspNetCompiler.Debug = "False"
        SlnRelativePath = "C:\WebProject1\"
    EndProjectSection
EndProject
Share:
25,214
Dominik G
Author by

Dominik G

Quality Manager / Developer with interests in all topics of computer science

Updated on July 17, 2022

Comments

  • Dominik G
    Dominik G almost 2 years

    we are running some of our sites as Web Site projects in Visual Studio. We recently upgraded to VS2015. Now we can't add virtual directories to new websites.

    We already tried right-click "Add new virtual direcory" where we get an error message as well as editing the applicationhost.config in the Project folder.

    Is this a bug with VS2015 or is there a way to create the directories? There is no problem with project that already ran on IIS Express before upgrading to VS2015.

    PS: I know of the thread here but it doesn't help.

  • Chartreugz
    Chartreugz about 7 years
    This answer worked for me, but I had to delete the applicationhost.config file located in the hidden .vs folder that IIS Express uses to determine application structure. Once I ran the web site, IIS Express configured the application with the correct virtual directory. Thanks!
  • Uwe Keim
    Uwe Keim almost 7 years
    Works perfectly for me. Thanks a lot! I had to enable hiddden folders, then I saw the ".vs" folder and then I modified the ".vs\config\applicationhost.config" file as described in your answer.
  • qxotk
    qxotk almost 4 years
    I have successfully used this method to add specific virtual folders that are outside the project - e.g. /mywebsite/folders... is where most of my code is. I have some images in /someotherfolder/folders/images/... and I have a virtual folder set to point from /mywebsite/images/... -> /someotherfolder/folders/images/... - Should I be able to see this particular folder inside the solution explorer view?