Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Is it possible to define a virtual directory in IIS and somehow make the files in that directory relative to the physical directory and not to the virtual directory ?

For instance on my server I have the following folders: D:\WebSite\Css\myTheme.css, D:\WebSite\Images\image1.jpg

I created a virtual directory on IIS resources.mysite: Inside my website I reference the sheet like this resources.mysite/myTheme.css

But inside myTheme.css I reference pictures from ../Images/images1.jpg.

So the problem is that image1.jpg is not found because it is relative to the physical folder and not the virtual folder on IIS.

Can I solve this problem without modifying the style sheet ?

share|improve this question

2 Answers 2

One trivial solution to that problem is to use URL Rewrite (http://www.iis.net/download/URLRewrite) to expose the same /CSS/myTheme.css directly over /myTheme.css, that way when the browser resolves the relative URLs it will resolve them correctly. So that should work, I should also mention that IIS URL Rewrite is EXTREMELY performant and plays nice with kernel caching and more that would not affect any performance.

So in other words just install URL Rewrite and create a web.config file at the root of your site with the following and you should be good to go.

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Expose Theme CSS" stopProcessing="true">
          <match url="^myTheme.css" />
          <action type="Rewrite" url="/CSS/myTheme.css" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
share|improve this answer

No. You can't use the ../ to get to a high level folder than the root folder (of the site or the virtual directory, whichever applies).

This would be a major security issue if you could. People could do things like http://yoursite.com/../../../../Windows/System32/Config/SYSTEM and start downloading your registry, or the SAM database or who know what else they'd find interesting.

share|improve this answer
    
ahh remember when IIS 4(i think maybe 5 too) would let you do this :) –  Zypher May 23 '10 at 16:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.