9

I'm configuring a site in applicationhost.config for IIS 7.5 Express:

<site name="default" id="1" serverAutoStart="true">
    <application path="/">
        <virtualDirectory path="/" physicalPath="%IIS_BIN%\..\Somewhere\Else" />
                                            <!-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -->
    </application>
    ...
</site>

I've found that specifying relative paths as shown does not seem to work and will lead to an HTTP 500.19 Internal Server Error. IIS further reports error code 0x8007007b, which, after some googling, seems to indicate an invalid file path syntax.

Is there any way around this error, so that I can use relative physical path for my site's root?

stakx
  • 195
  • 1
  • 7

2 Answers2

6

Unfortunately no. That must be a full physical path. As long as you don't plan to change your site path often, a static path shouldn't be a problem. If you change your path often to different site instances you may want to consider using appcmd to script the change so that it gets all subfolders.

Scott Forsyth
  • 16,339
  • 3
  • 36
  • 55
  • 1
    If would be nice for dev for example when branching if the Vdir could be relative to the configuration file which could be checked into source control. Any ideas on how to do this? – PilotBob Aug 27 '15 at 21:14
  • 3
    Relative paths aren't supported with the current versions of IIS, unfortunately, so the cleanest solution is to use the same path on each machine. If you must have different paths on different machines (I assume dev machines) then you can try an environment variable. Create a system environment variable so that it's available to IIS and use that for the root of the path on the individual systems. – Scott Forsyth Aug 28 '15 at 03:43
  • 2
    It seems that some environment variables are supported, though, e.g. ``. – Uwe Keim Jan 19 '16 at 11:53
  • @UweKeim You're right, this does work with the current version(s) of IIS. IIS 10 supports variables in the physicalPath now. Note that %IIS_SITES_HOME% is for IIS Express. That variable doesn't exist in the full version of IIS. However, other system variables do work. – Scott Forsyth Jan 22 '16 at 23:18
0

You don't say how you run IIS Express. If you run it from command line then you can try a workaround with creating and environment variable which you can use in physicalPath.

For example if you have two files: run_on_iisexpress.ps1 and run_on_iisexpress_applicationhost.config in one directory. In run_on_iisexpress.ps1 script that runs IIS you can create an environment variable with absolute url.

run_on_iisexpress.ps1

$applicationhostConfig = "$PSScriptRoot\run_on_iisexpress_applicationhost.config"
$env:MY_WEBSITE_PATH = $PSScriptRoot; #or any other logic to generate absolute path from relative path (Resolve-Path command is usefull here)
&"C:\Program Files\IIS Express\iisexpress.exe" /config:"$applicationhostConfig" /site:"MyWebsite" /apppool:"Clr4IntegratedAppPool"

run_on_iisexpress_applicationhost.config

...
<site name="MyWebsite" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="%MY_WEBSITE_PATH%" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:60001:localhost" />
    </bindings>
</site>
...
CichyK24
  • 101
  • 2