Recipe12.5.Creating Virtual Directories


Recipe 12.5. Creating Virtual Directories

Problem

You want to create a virtual directory for a web site.

Solution

Using a graphical user interface

To create a new virtual directory using a wizard, do the following:

  1. Open Internet Information Services (IIS) Manager.

  2. In the left pane, expand the Web Sites node under the server node.

  3. Right-click on the node for the web site you want to configure, select New Virtual Directory Creation Wizard, and click Next.

  4. Specify an alias for your virtual directory and click Next.

  5. Specify the absolute path (for a local virtual directory) or UNC path (for a remote virtual directory) to the folder or share where the content is located and click Next.

  6. Specify web permissions to control access to your virtual directory and click Next, then Finish.

To create a virtual directory using a previously saved configuration file, do the following:

  1. Open Internet Information Services (IIS) Manager.

  2. In the left pane, expand the Web Sites node under the server node.

  3. Right-click on the node for the web site you want to configure and select New

    Specify the path to the XML file containing the saved IIS configuration, click Read File, select the virtual directory you want to import, and click OK.

  4. If the saved configuration was password protected when it was created, you'll be prompted here for a password; enter it, and click OK.

To create a virtual directory using Windows Explorer, do the following:

  1. Open Windows Explorer, right-click the physical directory you want to create an alias for, and click Sharing and Security.

  2. Select the Web Sharing tab.

  3. Specify the web site in which your virtual directory will be located.

  4. Click Share this folder.

  5. Type an alias for your virtual directory, modify its web permissions if desired, and click OK twice.

Using a command-line interface

The following command creates a virtual directory within the Human Resources web site and maps alias employees to physical directory D:\resumes:

> iisvdir /create "Human Resources" employees D:\resumes

To list virtual directories within the Human Resources site:

> iisvdir /query "Human Resources"

To delete the previously created virtual directory:

> iisvdir /delete "Human Resources\employees"

Using VBScript
' This code creates a virtual directory in the default Web Site ' ------ SCRIPT CONFIGURATION ------ strComputer = "rallen-w2k3" strVdirName = "<VdirName>"  'e.g., employees strVdirPath = "<Path>"      'e.g., D:\resumes ' ------ END CONFIGURATION --------- set objIIS = GetObject("IIS://" & strComputer & "/W3SVC/1") set objweb site = objIIS.GetObject("IISWebVirtualDir","Root") set objVdir = objweb site.Create("IISWebVirtualDir",strVdirName) objVdir.AccessRead = True objVdir.Path = strVdirPath objVdir.SetInfo WScript.Echo "Successfully created virtual directory: " & objVdir.Name

Discussion

A virtual directory is a directory that behaves from the client perspective as if it is a subdirectory of a web site, whereas the actual directory may reside in a different location on the web server's hard drive or even on a different server on the network. A local virtual directory is one that maps to a folder on the local computer's file structure, while a remote virtual directory is one that maps to a shared folder on the network. The main purpose of virtual directories is to provide administrators with flexibility in how they host content for web sites.

Using a command-line interface

The iisvdir.vbs command can be used only to create local virtual directories, not remote ones. In other words, if the directory containing the web content is a shared folder on a different server (such as a file server) and you want to create a virtual directory on your IIS computer that maps to this shared folder, you can't use the iisvdir.vbs script to do this.

See Also

MS KB 816568 (HOW TO: Manage Web Sites and Web Virtual Directories by Using Command-Line Scripts in IIS 6.0), MS KB 247376 (WWW and FTP Virtual Directories Are Not Displayed in Directory Listings), and MS KB 311626 (How to: Rename a Virtual Directory in IIS 6.0)



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

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