다음을 통해 공유


Using Virtual Directories

Applies To: Windows Server 2003, Windows Server 2003 R2, Windows Server 2003 with SP1

A virtual directory is a friendly name, or alias, either for a physical directory on your server hard drive that does not reside in the home directory, or for the home directory on another computer. Because an alias is usually shorter than the path of the physical directory, it is more convenient for users to type. The use of aliases is also secure because users do not know where your files are physically located on the server and therefore cannot use that information to modify your files. Aliases also make it easier for you to move directories in your site. Rather than changing the URL for the directory, you change the mapping between the alias and the physical location of the directory.

If your Web site contains files that are located in a directory other than the home directory, or on other computers, you must create virtual directories to include those files in your Web site. To use a directory on another computer, you must specify the directory's Universal Naming Convention (UNC) name, and provide a user name and password for access rights.

If you want to publish from any directory not contained within your home directory, you must create a virtual directory. For example, suppose you are setting up a Web site for your marketing team on your company's intranet. The following table shows the mapping between the physical location of the files and the URL that accesses the files.

Physical Location Alias URL

C:\Inetpub\wwwroot

home directory (none)

https://SampleWebSite

\\Server2\SalesData

Customers

https://SampleWebSite/Customers

D:\Inetpub\wwwroot\Quotes

None

https://SampleWebSite/Quotes

D:\Inetpub\wwwroot\OrderStatus

None

https://SampleWebSite/OrderStatus

D:\Marketing\PublicRel

PR

https://SampleWebSite/PR

Both virtual directories and physical directories (directories without an alias) appear in IIS Manager. A virtual directory is indicated by a gear icon. The following illustration shows the Web site example described above, where /Customers and /PR are virtual directories.

Art Image

For a simple Web site, you might not need to add virtual directories. You can simply place all of your files in the site's home directory. If you have a complex site, or want to specify different URLs for different parts of your site, you can add virtual directories as needed. To make a virtual directory accessible from multiple sites, you must add the virtual directory to each site.

There are three ways to create or delete a virtual directory:

  • Using IIS Manager; either using the Virtual Directory Creation Wizard or by importing a configuration file.

  • Using Windows Explorer (this method requires that your hard drive is formatted with the NTFS file system).

  • Using the Iisvdir.vbs administration script.

Important

You must be a member of the Administrators group on the local computer to perform the following procedure or procedures. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run IIS Manager as an administrator. At a command prompt, type runas /User:Administrative_AccountName "mmc %systemroot%\system32\inetsrv\iis.msc".

Procedures

To create a virtual directory using the Virtual Directory Creation Wizard

  1. In IIS Manager, double-click the local computer, double-click the Web site or FTP site to which you want to add a virtual directory, right-click the Web Site or folder within which you want to create the virtual directory, point to New, and then click Virtual Directory.

  2. Click Next.

  3. In the Alias box, type a name for the virtual directory, and then click Next. The alias is the name that the user types, and it should be short and easy to type.

  4. In the Directory box, type or browse to the physical directory in which the virtual directory resides, and then click Next.

  5. In the Access Permissions dialog box, set the access permissions appropriate to your needs.

  6. Click Next, and then click Finish.

To create a virtual directory by importing a configuration file

  1. In IIS Manager, double-click the Web site or FTP site to which you want to add a virtual directory, right-click the Web Site or folder within which you want to create the virtual directory, point to New, then click Virtual Directory (from file).

  2. Click Next.

  3. In the Import configuration box, click Browse and navigate to the file containing the virtual directory configuration to import.

  4. Click Read File, click the virtual directory configuration to import, and then click OK.

Note

The following method is available only if your server's hard disk is formatted with the NTFS file system.

To create a virtual directory using Windows Explorer

  1. In Windows Explorer, browse to the folder where to want to create a virtual directory for your site, right-click the directory, and click Sharing and Security.

  2. Click the Web Sharing tab, and in the Share on list box, click the site for which you are creating a virtual directory, and click Share this folder.

  3. In the Alias box, type an alias name for this virtual directory.

  4. Set the Access permissions and Applications permissions by clicking the appropriate settings.

  5. Click OK, and then click OK again. You can verify that the virtual directory was created by starting IIS Manager and double-clicking the Web site.

Important

You must be a member of the Administrators group on the local computer to run scripts and executables. As a security best practice, log on to your computer by using an account that is not in the Administrators group, and then use the runas command to run your script or executable as an administrator. At a command prompt, type runas/profile /User:MyComputer\Administratorcmd to open a command window with administrator rights and then type cscript.exe ScriptName (include the script's full path and any parameters).

To create a virtual directory using the Iisvdir.vbs administration script

  1. From the Start menu, click Run.

  2. In the Open box, type cscript iisvdir.vbs /create "SampleWebSite" VirtualDirectoryName x:\path. Substitute your Web site name, virtual directory name, and path to the physical directory as appropriate.

  3. Click OK.

Note

Deleting a virtual directory does not delete the corresponding physical directory or files.

To delete a virtual directory using IIS Manager

  1. In IIS Manager, expand the site containing the virtual directory you want to delete, right-click the virtual directory, click Delete, and then click Yes.

To delete a virtual directory using Windows Explorer

  1. In Windows Explorer, browse to the folder containing the virtual directory you want to delete, right-click the directory, and click Sharing and Security.

  2. Click the Web Sharing tab, click Remove, and then click Yes.

  3. Click OK. You can verify that the virtual directory was deleted by starting IIS Manager and double-clicking the Web site.

Note

The following method does not work for root virtual directories.

To delete a virtual directory using the Iisvdir.vbs administration script

  1. From the Start menu, click Run.

  2. In the Open box, type cscript iisvdir.vbs /delete "SampleWebSite" VirtualDirectoryName. Substitute your Web site name and virtual directory name as appropriate.

  • For detailed information about the Iisvdir.vbs command-line administration script, search for "Iisvdir.vbs" in Help and Support Center for Windows Server 2003.

  • For information about Security for virtual directories, see Securing Virtual Directories and "Access control" in Help and Support Center for Windows Server 2003.