title: Is it possible to use a Relative path when setting a custom error page in IIS7?
body: <p>I'm trying to set a custom 404 error page for my web application. The trouble is that this application will be deployed to a number of different environments. Sometimes it will be in a virtual directory and sometimes it won't.</p>
  
  <p>I have the error page in a directory called ErrorPages and have set up my config like this:</p>
  
  <pre><code>   &lt;httpErrors errorMode="Custom" existingResponse="Replace"&gt;
       &lt;remove statusCode="404"/&gt;
       &lt;error statusCode="404" path="/VirtualDir/ErrorPages/404.aspx" responseMode="ExecuteURL" /&gt;
     &lt;/httpErrors&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>The trouble is when I deploy this to the root of a web site, the <code>/VirtualDir</code> part needs to be removed. If I remove it before deployment then I need to add it back in when deploying to a virtual directory. Is there any way I can set the path to be <em>relative to the virtual directory</em> and not to the site?</p>
  
  <p>I have tried using a <code>~</code>, but that does not work either, like this:</p>
  
  <pre><code>   &lt;httpErrors errorMode="Custom" existingResponse="Replace"&gt;
       &lt;remove statusCode="404"/&gt;
       &lt;error statusCode="404" path="~/ErrorPages/404.aspx" responseMode="ExecuteURL" /&gt;
     &lt;/httpErrors&gt;
  &lt;/system.webServer&gt;
  </code></pre>