Managing Virtual Directories

A lot of what you learned in the preceding section applies to many of the other admin scripts included with IIS 6 (particularly the /s, /u, and /p switches, which can be used with any of the scripts to run them from a remote Windows Server 2003 machine), so we’ll move more quickly through the remaining scripts. Next, we’ll look at how to create, delete, and query virtual directories.

Creating Virtual Directories

For these examples, you’ll work with the Accounting website with a home directory of C:\finance that you created earlier. Start by creating a virtual directory with an alias of “budget” that maps to the physical directory C:\planning:

C:\>iisvdir /create Accounting budget C:\planning Connecting to server ...Done. Virtual Path  = Accounting/ROOT/budget ROOT          = C:\planning Metabase Path = W3SVC/376238833/ROOT/budget

The output should be easy to understand now after what you learned in the preceding section. Open IIS Manager and verify that the virtual directory exists and has the settings you expected (Figure 11-14).

click to expand
Figure 11-14: Virtual directory created using iisvdir.vbs

start sidebar
Invisible Virtual Directories

Something you need to watch out for when creating virtual directories (with either iisvdir.vbs or IIS Manager) is invisible virtual directories. This happens when the alias for a virtual directory is identical to a physical subdirectory within the website root folder. For example, say your website home directory is C:\Inetpub\wwwroot, as it is for the Default Web Site, and you create a physical subdirectory \test under \wwwroot. If users want to access the default.htm file located in this directory, they can open the URL http://servername/test on the client machine. But what if you now create a virtual directory within your site and give it the alias “test” and map this to a folder called C:\stuff. Now you have a problem, because when a user tries to open the same URL http://servername/test, IIS will assume you want the contents of the virtual directory and will return the default.htm file from C:\stuff. The result is that once you create your test virtual directory, users can no longer access the files in the physical \test directory! Watch out for this!

end sidebar

Now create another virtual directory, this time within the existing virtual directory called budget that you just created. The new virtual directory should have the alias 2003 and be mapped to C:\planning\2003 as its content location:

C:\>iisvdir /create Accounting/budget 2003 C:\planning\2003 Connecting to server ...Done. Virtual Path  = Accounting/ROOT/budget/2003 ROOT          = C:\planning\2003 Metabase Path = W3SVC/376238833/ROOT/budget/2003

Verify in IIS Manager that a new 2003 virtual directory exists below “budget” in the console tree. Easy as pie!

Querying Virtual Directories

Just as you can use iisweb.vbs to display the websites on your machine, you can use iisvdir.vbs to display the virtual directories within a website:

C:\>iisvdir /query Accounting Connecting to server ...Done. Alias                              Physical Root ============================================================================== /budget                            C:\planning

Note that running /query against a website does not recursively list all virtual directories on the machine, but only those beneath the root. To display virtual directories within virtual directories, try this:

C:\>iisvdir /query Accounting\budget Connecting to server ...Done. Alias                              Physical Root ============================================================================== /2003                              C:\planning\2003

And if you try to go even deeper, here’s what happens:

C:\>iisvdir /query Accounting\budget\2003 Connecting to server ...Done. No virtual sub-directories available.

Deleting Virtual Directories

Now delete the 2003 virtual directory you created earlier:

C:\>iisvdir /delete Accounting\budget\2003 Connecting to server ...Done. Web directory Accounting/ROOT/budget/2003 has been DELETED

Now confirm that 2003 has been deleted:

C:\>iisvdir /query Accounting\budget Connecting to server ...Done. No virtual sub-directories available.

Like websites, deleting a virtual directory does not delete its associated content directory.




IIS 6 Administration
IIS 6 Administration
ISBN: 0072194855
EAN: 2147483647
Year: 2003
Pages: 131
Authors: Mitch Tulloch

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net