IIS (3/9)

Physical Directories

The website contents we have seen in the previous page were trivial. A real website will have its contents organized across several directories. The first simple way to have directories is simply to create them in the directory where the website contents are, in the case of the default website that is C:\inetpub\wwwroot. To illustrate this let's create a directory called SubDir1 in C:\inetpub\wwwroot and put in that new directory a file called index.html with the following contents:

File: SubDir1/index.html
<html>
<head><title>Subdirectory</title></head>
<body>
<p>This is the index.html file in SubDir1.</p>
</body>
</html>

The IIS Manager now shows the new directory in the default website (figure 1).

IIS Manager with directory
Figure 1: The IIS Manager with a directory

We can now simply navigate to SubDir1/index.html by entering the following URL in the browser: http://localhost/SubDir1 and the contents of SubDir1/index.html will be displayed in the browser. As you can see nothing special was needed to make this work. A subdirectory created in C:\inetpub\wwwroot can easily be accessed using a URL matching the directory structure.

Virtual Directories

As we saw in the previous section there is straightforward mapping between URLs and the directory tree under C:\inetpub\wwwroot. But what if that is not what we want. For instance we may want http://localhost/mystuff to map to C:\inetpub\wwwroot\SubDir1\SubDir2\SubDir3 because we don't want visitors to have to type or remember such a long URL. This is where virtual directories come in play. So let's go through the steps needed to create the mystuff virtual directory. First we right-click on the Default Website in the IIS Manager which brings up the contextual menu shown in figure 2 and select "Add Virtual Directory...". We could also have used the Add Virtual Directory shortcut in the right-hand side column. This brings up the dialog to set up the virtual directory as shown in figure 3.

IIS Manager: adding a virtual directory
Figure 2: Adding a virtual directory in the IIS Manager


IIS Manager: virtual directory setup
Figure 3: Setting up a virtual directory in the IIS Manager

As you can see the setup is straightforward. You specify the alias i.e. what will be used in the URL and the path of the physical directory you want to associate with the alias. Once this is done the IIS Manager screen will look as shown in figure 4.

IIS Manager with a virtual directory
Figure 4: The IIS Manager with a virtual directory

On that screen you can see the newly created virtual directory. Virtual directories are distinguished from physical directories by the presence of a little arrow in the bottom left corner similar to a Windows shortcut. You can now enter http://localhost/mystuff to access C:\inetpub\wwwroot\SubDir1\SubDir2\SubDir3\index.html. Note that http://localhost/SubDir1/SubDir2/SubDir3 also still works.


blog comments powered by Disqus

Copyright(c) 2006-2015 Xavier Leclercq | Privacy policy

Home
Contact Us
Search