Recipe 12.5. Creating Virtual DirectoriesProblemYou want to create a virtual directory for a web site. SolutionUsing a graphical user interfaceTo create a new virtual directory using a wizard, do the following:
To create a virtual directory using a previously saved configuration file, do the following:
To create a virtual directory using Windows Explorer, do the following:
Using a command-line interfaceThe 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 DiscussionA 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 interfaceThe 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 AlsoMS 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) |