I had a requirement of late where by I wanted to share a Master Page over many physical sub sites, i.e.
- Main Website (www.mainsite.com)
- Sub Site 1 (www.subsite1.com)
- Sub Site 2 (www.subsite2.com)
- etc…
It was at this point when I thought of virtual directories and really just, again, stood back and admired the work which must have gone into such a methodology and the output which is so simple to use and yet so powerful. If you have not used Virtual Directories before or you have heard of them but not quite GOT what they are about or their purpose then you may find this post useful.
Ignoring the master pages for now, say that you want to share a common CSS style sheet across many different websites, with the style sheet residing inside a main website. So here is an example folder structure of the main website or a snippet:
Ok, now I zip over to my other physical web site in IIS called www.subsite1.com and before I do anything, I right click and add a virtual directory. I give it an alias of assets and point it at the physical path of the above assets folder inside the www.mainsite.com website folder. Now once you have done this, you will see a folder with a shortcut icon, i.e. Virtual.
What does this mean? Well if you then create a simple html page, and you want to include the css, your css line would be the same as the one used for the www.mainsite.com .
www.mainsite.com –> /assets/css/sharedStyle.css
www.subsite1.com –> /assets/css/sharedStyle.css
If you were to go inside the folder for www.subsite1.com inside windows explorer, all you would see is this simple html page you made, and not the actual folder you are referencing, so it is virtual in every sense, albeit 1, of the word.
So if you need to change any common styles, for the many websites which used the above style sheet in my example you have consolidated the changes to one single location.
