Managing Websites with IIS Manager (part 1) - Creating a Virtual Directory

10/17/2010 5:24:07 PM

When IIS is installed, it automatically creates a directory named c:\inetpub\wwwroot, which represents your website. Any files in this directory will appear as though they're in the root of your web server.

To add more pages to your web server, you can copy HTML, ASP, or ASP.NET files directly to the c:\inetpub\wwwroot directory. For example, if you add the file TestFile.html to this directory, you can request it in a browser through the URL http://localhost/TestFile.html. You can even create subdirectories to group related resources. For example, you can access the file c:\inetpub\wwwroot\MySite\MyFile.html through a browser using the URL http://localhost/MySite/MyFile.html.

Using the wwwroot directory is straightforward, but it makes for poor organization. To properly use ASP or ASP.NET, you need to make your own virtual directory for each web application you create. With a virtual directory, you can expose any physical directory (on any drive on your computer) on your web server as though it were located in the c:\inetpub\wwwroot directory.

Before you get started, you need to launch IIS Manager. To do so, open the Start menu, and type "IIS Manager" in the search box. When the Internet Information Services (IIS) Manager shortcut appears, click it.

The first thing you'll notice about IIS Manager is the tree structure on the left side. Initially, this tree shows a single item—your computer. Underneath are two groups, named Application Pools and Sites, respectively. If you expand the Sites group and then expand the Default Web Site item inside, you'll see all the virtual directories that are currently configured on the computer. Each one represents a separate web application.

Figure 1 shows the IIS Manager window. It's divided into three parts:

  • On the left side is the website tree. In Figure 1, there are two web applications in the website tree: EightBall and SampleApp.

  • In the middle is a useful set of icons that allow you to perform various configuration tasks with the currently selected item in the tree, which is usually a website folder. These icons are part of Features View. Alternatively, you can switch to Content View by clicking the Content View button at the bottom of the pane. In this case, you'll simply see the contents of the selected folder. Click Features View to switch back.

  • On the right side is the Actions pane, which includes links that let you quickly perform a few of the most common tasks (again, based on the currently selected item in the tree). This is a standard design that's used in several Windows management tools.

Figure 1. IIS Manager

Now that you've taken your first look at IIS Manager, you're ready to get started managing your websites. In the next section, you'll learn how to create your first virtual directory.

1. Creating a Virtual Directory

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, and expand the Sites node underneath.

  2. Right-click the Default Web Site item, and choose Add Application. The Add Application dialog box appears, which requests several pieces of information (Figure 2).

    Figure 2. Creating a web application
  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. Next, you need to choose the physical path. This is the 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. Next, you need to specify the application pool. An application pool is a group of settings that applies to one or more web applications (as described in the next section). Although the standard DefaultAppPool option seems compelling, it actually isn't what you want, because it relies on ASP.NET 2.0. To give your virtual directory the ability to host ASP.NET 4, you need to explicitly choose the application pool named ASP.NET v4.0. To do so, click the Select button, pick it from the "Application pool" list, and then click OK.

  6. To finish the process, 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 selecting it and using the icons in the Features View on the right.

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 MyApp and it contains the page MyPage.aspx, you should be able to request http://localhost/MyApplication/MyPage.aspx.


Imagine you create a virtual directory called MyApp on a computer called MyServer. The virtual directory corresponds to the physical directory c:\MyApp. If you add the subdirectory c:\MyApp\MoreFiles, this directory will automatically be included in the IIS tree as an ordinary folder. Clients will be able to access files in this folder by specifying the folder name, as in http://MyServer/MyApp/MoreFiles/SomeFile.html.

By default, the subdirectory will inherit all the permissions of the virtual directory. However, you can change these settings using the IIS Manager. This is a common technique used to break a single application into different parts (for example, if some pages require heightened security settings).

This is also the source of a common mistake in ASP.NET deployment. To understand the problem, imagine you have a website in a folder named c:\Applications\WebApps\Site1. This is the directory you should use when you create your virtual directory. However, if you accidentally create a virtual directory for the parent directory c:\Applications\WebApps, you might not realize the error right away. That's because you'll still be able to access the files in Site1 (because it's a subdirectory of your virtual directory WebApps). However, when you try to request one of the web pages inside Site1, you'll receive an error page informing you that the settings in the web.config file aren't valid. The problem is that certain settings are valid only at the application level, not the subdirectory level. To solve this problem, remove the incorrect virtual directory and create the one you really want.

Other -----------------
- Deploying ASP.NET 4 Applications with Visual Studio (part 2) - Copying a Website and Publishing a Website
- Deploying ASP.NET 4 Applications with Visual Studio (part 1) - Creating a Virtual Directory for a New Project
- Writing Your First Service in Visual Basic 2008 (part 3)
- Writing Your First Service in Visual Basic 2008 (part 2)
- Writing Your First Service in Visual Basic 2008 (part 1)
Most View
- Windows Phone 7 with Silverlight : Working with the Phone
- SQL Server 2008 R2 : Replication - What Is Replication?
- Administering SQL Server 2008 with PowerShell : PowerShell Scripting Basics (part 1)
- Exchange Server 2010 : Manage Web-Based Email Access (part 1) - Configure OWA URLs
- Windows 7 : Reviewing Event Viewer Logs
- Administering SQL Server 2008 with PowerShell : Step-By-Step Examples (part 1) - General Tasks & Scheduling Scripts
- Windows Server 2008 : Configuring IIS Security (part 9)
- Performing SharePoint 2010 Installations (part 3)
- SharePoint 2010 : Check In and Check Out a File or List Item
- Windows 7 : Adding Folders and Files to the Default Website (part 3) - Adding a Folder to the Default Website
Top 10
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 3) - Configuring Recipient Filtering
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 2)
- Implementing Edge Services for an Exchange Server 2007 Environment : Utilizing the Basic Sender and Recipient Connection Filters (part 1)
- Implementing Edge Services for an Exchange Server 2007 Environment : Installing and Configuring the Edge Transport Server Components
- What's New in SharePoint 2013 (part 7) - BCS
- What's New in SharePoint 2013 (part 6) - SEARCH
- What's New in SharePoint 2013 (part 6) - WEB CONTENT MANAGEMENT
- What's New in SharePoint 2013 (part 5) - ENTERPRISE CONTENT MANAGEMENT
- What's New in SharePoint 2013 (part 4) - WORKFLOWS
- What's New in SharePoint 2013 (part 3) - REMOTE EVENTS