Tuesday, January 15, 2013

How to Create Virtual Directory in IIS

When you’re ready to deploy a website on a computer that has IIS, the first step you’ll usually take is to create the physical directory where the pages will be stored (for example, c:\MySite). The second step is to expose this physical directory as a virtual directory through IIS. This means the website becomes publicly visible to other computers that are connected to your computer. Ordinarily, a remote computer won’t be allowed to access your c:\MySite directory. However, if you map c:\MySite to a virtual directory, the remote user will be able to request the files in the directory through IIS.

Before going any further, choose the directory you want to expose as a virtual directory. You can use any directory you want, on any drive, and you can place it as many levels deep as makes sense. You can use a directory that already has your website files, or you can copy these files after you create the virtual directory. Either way, the first step is to register this directory with IIS.

The easiest and most flexible way to create a virtual directory is to use the IIS Manager utility. Here’s what you need to do:

1. To create a new virtual directory for an existing physical directory, expand the node for the current computer, expand the Web Sites node underneath, and then right-click the Default Web Site item.

2. If you’re using IIS 5 or IIS 6, choose New -> Virtual Directory from the context menu. A wizard will start to manage the process (see Figure - 1). As you step through the wizard, you’ll be asked to supply the information IIS needs. If you’re using IIS 7, choose Add Application directory. You’ll be asked to supply essentially the same information, but in a single window (see Figure - 2).

Figure - 1

Figure - 2

3. The first piece of information you need to supply is the alias—the name a remote client will use to access the files in this virtual directory. For example, if your alias is MyApp and your computer is MyServer, you can request pages using URLs such as http://MyServer/MyApp/MyPage.aspx.

4. Choose a directory. The directory is the physical directory on your hard drive that will be exposed as a virtual directory. For example, c:\Inetpub\wwwroot is the physical directory that is used for the root virtual directory of your web server. IIS will provide access to all the allowed file types in this directory.

5. If you’re using IIS 5 or IIS 6, there’s one more step. You need to choose the permissions for your virtual directory. To host an ASP.NET application, you need only to enable the read and execute permissions (the first two check boxes). If you’re using a development computer that will never act as a live web server, you can allow additional permissions. (Keep in mind, however, that this could allow other users on a local network to access and modify files in the virtual directory.)

6. If you’re using IIS 7, you can also specify the application pool by clicking the Select button. An application pool is a group of settings that applies to one or more applications. 

7. To finish the process in IIS 5 or IIS 6, advance to the end of the wizard and then click Next. In IIS 7, you simply need to click OK in the Add Virtual Directory dialog box. 

When you finish these steps, you’ll see your new virtual directory appear in the list in IIS Manager. You can remove an existing virtual directory by selecting it and pressing the Delete key, or you can change its settings by right-clicking it and choosing Properties (in IIS 5 and IIS 6) or selecting it and using the icons in the Features View on the right (in IIS 7).

Once you’ve created your virtual directory, fire up a browser to make sure it works. For example, if you’ve created the virtual directory with the alias MyApplication and it contains the page MyPage.aspx, you should be able to request http://localhost/MyApplication/MyPage.aspx. 

No comments:
Write comments
Recommended Posts × +