Create a Virtual Directory (IIS 7)
Applies To: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista
A virtual directory is a directory name, used in an address, which corresponds to a physical directory on the server. You can add a virtual directory that will include directory content in a site or an application without having to move the content physically into that site or application directory.
For information about the levels at which you can perform this procedure, and the modules, handlers, and permissions that are required to perform this procedure, see Virtual Directories Feature Requirements (IIS 7).
Exceptions to feature requirements
- Only server administrators can add and edit virtual directories.
To add a virtual directory
You can perform this procedure by using the user interface (UI), by running Appcmd.exe commands in a command-line window, by editing configuration files directly, or by writing WMI scripts.
To use the UI
Open IIS Manager. For information about opening IIS Manager, see Open IIS Manager (IIS 7).
In the Connections pane, expand the Sites node in the tree, and then click to select the site in which you want to create a virtual directory.
In the Actions pane, click View Virtual Directories.
On the Virtual Directories page, in the Actions pane, click Add Virtual Directory.
In the Add Virtual Directory dialog box, type a name in the Alias text box. This alias is used to access the content from a URL.
In the Physical path text box, type the physical path of the content folder, or click Browse to navigate through the file system to find the folder.
Optionally, click Connect as to specify credentials that have permission to access the physical path. If you do not use specific credentials, select the Application user (pass-through authentication) option in the Connect As dialog box.
Optionally, click Test Settings to verify the settings that you specified for the virtual directory.
To add a virtual directory to the root application in a site, use the following syntax:
**appcmd add vdir /app.name:string/ /path:**string **/physicalPath:**string
The variable app.namestring is the site name and the / following the name specifies that the virtual directory should be added to the root application of the site. The variable pathstring is the virtual path of the virtual directory, such as /photos, and physicalPathstring is the physical path of the virtual directory's content in the file system.
For example, to add a virtual directory named photos with a physical location of c:\images to the root application in a site named contoso, type the following at the command prompt, and then press ENTER:
appcmd add vdir /app.name:contoso/ /path:/photos /physicalPath:c:\images
To add a virtual directory to an application other than a site's root application, type the name of the application after / in app.namestring. For example, to add the same virtual directory used in the previous example to an application named marketing in a site named contoso, type the following at the command prompt, and then press ENTER:
appcmd add vdir /app.name:contoso/marketing /path:/photos /physicalPath:c:\images
For more information about Appcmd.exe, see Appcmd.exe (IIS 7).
The procedure in this topic affects the following configuration elements:
<virtualDirectory> under <application> element
For more information about IIS 7 configuration, see IIS 7.0: IIS Settings Schema on MSDN.
Use the following WMI classes, methods, or properties to perform this procedure:
- VirtualDirectory.Create method
For more information about WMI and IIS, see Windows Management Instrumentation (WMI) in IIS 7. For more information about the classes, methods, or properties associated with this procedure, see the IIS WMI Provider Reference on the MSDN site.