Click here to Skip to main content
Click here to Skip to main content

Switching Physical Path of Website Using a Script

, 5 Jul 2011
Rate this:
Please Sign up or sign in to vote.
Switching IIS websites' physical location automatically

Table of Contents

Introduction

If we work on multiple releases simultaneously, the need to manually change IIS virtual directory settings to physically point to different folders everytime becomes cumbersome. This also becomes error-prone when there are multiple virtual directories under a website, so we may not switch the physical location correctly due to typos. This article shows how to switch IIS 6.0 websites' metadata and switch automatically using the iiscnfg.vbs script.

The Problem

Let's say company TheProductCompany's website is http:\\theproductcompany.com. Typically, TheProductCompany launches new products via its website every quarter.

For simplicity of coding, and so that development work for various releases corresponding to each quarter can continue in parallel, the physical location of the website is logically mapped as: d:\theproductcompany_Q1, d:\theproductcompany_Q2, etc. indicating code for various 'quarters'. For supporting code check-in to multiple releases, TheProductCompany uses multiple branches in their source control.

Now, a developer John is working on all of these websites. He finds it very tedious to go to IIS everytime and change the physical locations associated with the websites manually, viz. d:\theproductcompany_Q1, d:\theproductcompany_Q2, ...Q3, etc. everytime he has to work on various requirements on these various releases.

In a professional setting, there could be many virtual directories under your main website and each following a similar folder structure. This really becomes cumbersome and error-prone many-a-times.

The Solution

First of all, we need to set the virtual directory's physical path as usual. We need to export this configuration. The next time, after we have switched to d:\theproductcompany_Q2 and want to switch back to d:\theproductcompany_Q1, we need to import the already exported settings. This can be done by exporting/importing the IIS metadata as below.

Export Settings

First of all, we need to export our current IIS metadata/settings.

This can be done in two ways:

Exporting manually through IIS

  1. Open IIS
  2. On your websites, right click and select All Tasks. Click Save Configuration to file (see figure 1):

  3. Type in a file name (for our example - figure 2-: I typed in d:\myproduct.xml)

Exporting using the iisconfig.vbs file

The syntax is:

iiscnfg /export/f [Path\]FileName.xml/sp SourcePath [/d EncryptingPassword] 
[/inherited] [/children] [/s Computer [/u [Domain\]User [/p Password]]]

Import Settings

Now whenever we need to switch, just import:

iiscnfg /import /f [Path\]FileName.xml /sp SourcePath /dp DestiniationPath
[ /d EncryptingPassword] [ /inherited ] [ /children ] [ /merge ][ /s Computer 
[ /u [Domain\]User [ /p Password]]]

So John can now import:

iiscnfg /import /sp /lm/w3svc /dp /lm/w3svc /children /f d:\myproduct.xml; 

References

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

My Tech World

United States United States
No Biography provided

Comments and Discussions

 
QuestionHow should we do this on IIS 7.5 Pinmembervarshavmane7-Jul-11 20:52 
GeneralMy vote of 3 PinmemberShahriar Iqbal Chowdhury5-Jul-11 11:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140709.1 | Last Updated 5 Jul 2011
Article Copyright 2011 by My Tech World
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid