Search code examples
visual-studio-2013web-config.net-4.5iis-expressvirtual-directory

Adding multiple levels of virtual directory to application root in VS2013 MVC4 IIS express


I am using Visual Studion 2013 and MVC4. I am using areas in application and routing rules (RegisterArea overrides) for each area.

My company decided to move our web application one level up in live and now I have to append Calculator that to all javascript scripts, css and all other paths across application + do that for all Controllers

What I am talking about is from

http://host:1234/legal-services/Wills/Index

to http://host:1234/legal-services/Calculator/Wills/Index

so after replacing all the scripts I went to csproj and added override for application root so it would do override to all controllers, but this was completely ignored.

enter image description here

I am assuming when overriding host one only can work with hostname and port but not folders.

UPDATE: I have also tried directly modifying .csproj file to change IISUrl setting

from
<IISUrl>http://localhost:50766/legal-services/</IISUrl>
to
<IISUrl>http://localhost:50766/legal-services/Calculator/</IISUrl>

but this had no effect ether.

UPDATE2:

So change was in configuration in applicationHost.config in C:\Users\[username]\Documents\IISExpress\config, to add additional virtual directory

From

    <virtualDirectory path="/" physicalPath="C:\hg\Website" /> 
    <virtualDirectory path="/legal-services" physicalPath="C:\hg\Website" />

to

    <virtualDirectory path="/" physicalPath="C:\hg\Website" /> 
    <virtualDirectory path="/legal-services/calculator" physicalPath="C:\hg\Website" />

however now I am running into different issue since I am now dealing with multiple layers on virtual directories I got 403 and it makes perfect sense since path in the middle (/legal-services) is not within the list.

When I added

 <virtualDirectory path="/" physicalPath="C:\hg\Website" /> 
<virtualDirectory path="/legal-services/calculator" physicalPath="C:\hg\Website" />
<virtualDirectory path="/legal-services" physicalPath="C:\hg\Website" />

I got configuration error (I am assuming because all 3 paths are pointing to same directory)

It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS.

<authentication mode="Forms">

Which indicates that path is not identified as web application or there is web.config conflict.

How could configure this so that path="/legal-services/calculator" would be identified as application without web.config conflicts ?


Solution

  • So the solution was to create two separate application paths in applicationHost.config like following where main path has part of virtual directory path and second application has full virtual directory path like following:

    <site name="Website-Site" id="2">
         <application path="/" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/" physicalPath="C:\hg\Website" />
            <virtualDirectory path="/legal-services" physicalPath="C:\hg\" />
        </application> 
        <application path="/legal-services/Calculator" applicationPool="Clr4IntegratedAppPool">
            <virtualDirectory path="/" physicalPath="C:\hg\Website" />
        </application>              
        <bindings>
            <binding protocol="http" bindingInformation="*:50766:localhost" />
        </bindings>
    </site>
    

    Hope this saves you some time.