Search code examples
asp.netvisual-studio-2008virtual-directory

ASP.NET virtual directory _within_ VS2008


I'm building an ASP.NET 3.5 web application. When I run the project (using Visual Studio's built-in server), it needs to be able to access a network share as a virtual directory. I can't seem to find any information about how to do this.

The network resource is very large, is updated frequently, and is used by other developers and in other projects projects--not just me and mine.

I understand that I can create an IIS virtual directory to the network path once the site is deployed, but that doesn't help me while I'm debugging.


Solution

  • It's now possible to have both virtual directories and sub-applications with newer versions of Visual Studio and IIS Express.

    1. Open .vs\All\config\applicationhost.config in your text editor of choice, then navigate to the configuration/system.applicationHost/sites node.

    2. Update the site element that corresponds to your parent application, like so:

    Original:

    <site name="Web" id="1">
        <!-- parent application -->
        <application path="/" applicationPool="Clr4IntegratedAppPool">
            <!-- application root -->
            <virtualDirectory path="/" physicalPath="C:\Src\Web" />
        </application>
        <bindings>
            <binding protocol="http" bindingInformation="*:5706:localhost" />
            <binding protocol="https" bindingInformation="*:44300:localhost" />
        </bindings>
    </site>
    

    Modified:

    <site name="Web" id="1">
        <!-- parent application -->
        <application path="/" applicationPool="Clr4IntegratedAppPool">
            <!-- application root -->
            <virtualDirectory path="/" physicalPath="C:\Src\Web" />
            <!-- virtual directory -->
            <virtualDirectory path="/DocRoot" physicalPath="C:\Src\DocRoot" />
        </application>
        <!-- sub-application -->
        <application path="/FooBar" applicationPool="Clr4IntegratedAppPool">
            <!-- application root -->
            <virtualDirectory path="/" physicalPath="C:\Src\Foo Bar" />
            <!-- virtual directory; shared with parent app, so must be duplicated -->
            <virtualDirectory path="/DocRoot" physicalPath="C:\Src\DocRoot" />
        </application>
        <bindings>
            <binding protocol="http" bindingInformation="*:5706:localhost" />
            <binding protocol="https" bindingInformation="*:44300:localhost" />
        </bindings>
    </site>
    
    1. Save and restart IIS Express.