Section 18.1. Internet Information Server (IIS)


18.1. Internet Information Server (IIS)

IIS is Microsoft's web server that works in conjunction with ASP.NET. We will cover the topics relevant to developing and deploying ASP.NET web applications.

18.1.1. IIS Versions

This chapter assumes that you are using IIS 5 or 5.1, the versions that are included with the Windows 2000 and Windows XP operating systems, respectively. IIS 6 (included with Windows Server 2003) features a similar interface but adds enhanced options and a revamped request processing architecture. You can use all the instructions in this chapter to configure virtual directories in IIS 6.

You can determine which version of IIS is serving a page by enabling tracing on that page (add trace="true" to the Page directive) and looking for the value of SERVER_SOFTWARE under Server Variables. Alternatively, add a Label control to the form and set its Text property as follows :

 lblVersion.Text = Request.ServerVariables["Server_Software"]; 

If the page is being served from VS2005 rather than IIS, the value of SERVER_SOFTWARE will be blank.

18.1.2. Virtual Directories

When you work with web applications, you will frequently need to create, configure, or examine the properties of a virtual directory. Virtual directories in IIS are central to web applications. A virtual directory is any directory on the server, or accessible to the server, that has been made available by IIS to requests from the Web. Virtual directories are isomorphic with applications, i.e., each virtual directory is a separate application, and each IIS-served application must have a single virtual root directory.

Virtual directories are accessible to requests from browsers coming in over the Internet. The URL is the domain name , followed by the virtual directory and the web page (or service) file. For example, if an application with a starting web page called MyPage.aspx was using a virtual directory called MyVirtualDirectory , and the domain name of the hosting web server was SomeDomainName.com , the URL to access that application would be the following:

 http://www.SomeDomainName.com/MyVirtualDirectory/MyPage.aspx 

When a new web application is created in VS2005 and the Location is set to HTTP, an IIS virtual directory for the app is created automatically. If the Location is set to either File System (the default) or FTP, IIS does not come into play and no virtual directory is created. In these latter two cases, VS2005 provides its own built-in, lightweight web server to serve the pages during development only.

If you wish to deploy the app or look at the app in a browser by navigating using a URL, you will have to create the virtual directory manually using IIS.

For a discussion of the Location setting, see Chapter 2.


There are several ways to create a virtual directory in IIS:

  • Click Start Run. In the Run dialog box, enter inetmgr , and click on OK.

  • Click Start Control Panel Administrative Tools. Click on either Internet Information Services or Computer Management .

  • Right-click on My Computer and select Manage.

All of these techniques bring up the Microsoft Management Console (MMC) , which is used throughout Windows for displaying and controlling system functions. In the left pane is a hierarchical tree structure showing resources for the computer being managed. The right pane displays the child nodes of the currently selected node.

Depending on how you opened the MMC, you will have the Computer Management window or the IIS Window. The latter is one of the nodes within the former; both are fully equivalent except that the Computer Management window allows you to see nodes in addition to IIS.

Looking at Computer Management, the tree on the left has top-level nodes for System Tools, Storage, and Services and Applications. Drilling down through Services and Applications, then Internet Information Services, then Web Sites, to the Default Web Site, the MMC window should look something like that shown in Figure 18-1. If you opened the IIS window directly, you would see the same thing except the top level node would already be Internet Information Services.

Figure 18-1. Computer Management console

Click on Default Web Site. The contents of the default web site will be visible, as shown in Figure 18-2.

The Default Web Site corresponds to the physical directory c:\inetpub\ wwwroot unless you've changed it. When IIS is installed on a machine, it creates this directory, along

Figure 18-2. Virtual directories

with several subdirectories (beginning with the underscore character). If you open a browser window and enter the following URL, you will see the default page for the default web site:

 http://localhost 

If your web server is accessible over the Internet through a domain name, a remote user at a browser who entered that domain name as a URL (say for example, as the following), would see the same thing:

 http://www.SomeDomainName.com 

You will not see anything in the browser (other than help pages put up by IIS) unless one of the following conditions is true:

  • A suitably named file ( default.htm , default.asp , default.aspx , or iisstart.asp ) containing a valid web page exists in the physical directory.

  • Directory Browsing is enabled by right-clicking on Default Web Site, going to the Home Directory tab in the Default Web Site Properties dialog box, and checking the Directory browsing checkbox.

    Be aware that enabling Directory Browsing can be a serious gap in security. It is generally not something to do on a production site unless you have a very good reason and suitable security precautions are in place, such as stringent permissions.


Compare the contents of the default web site in Figure 18-2 with the actual contents of c:\ inetpub\wwwroot shown in Figure 18-3. You can see that all the files and directories in the physical directory are also in the default web site in Figure 18-2. These physical directories, such as images and _private , are normal directories with standard Explorer-style directory icons.

Figure 18-3. c:\inetpub\wwwroot

Other directories in the Default Web Site shown in Figure 18-2, such as _vti_bin and Printers , have a directory icon with a small globe on the lower-right corner. These are virtual directories , created either by IIS or by a developer.

Finally, some of the directories in the default web site shown in Figure 18-2 have an icon that looks like a cardboard box with a green thing inside (it's a package, get it?). These are web application directories . They can be either physical directories or virtual directories. The virtual directories created by developers are also application directories by default. This can be changed by right-clicking on the directory in question in the left pane, selecting Properties, then clicking the Create Application Settings button to make it an application directory or the Remove Application Settings button to convert the directory to a plain virtual directory.

When a new web application or web service is created in VS2005 and the Location is set to HTTP, the virtual directory is created. To access the web site in a browser, you must provide the web site name appended to a valid URL, such as one of the following:

 http://localhost/MyNewWebSite     http://MyDomain.com/MyNewWebSite 

In this case, VS2005 automatically creates a physical directory called MyNewWebSite . In the case of localhost, it will be located (by default) under c:\inetpub\wwwroot . In the case of a remote domain, the physical directory will be located under the virtual root of the domain. This new physical directory is both a virtual directory and an application directory.

You can make a new virtual directory outside VS2005 using the Computer Management window shown in Figure 18-2 (or the equivalent Internet Services Manager window) by right-clicking on Default Web Site in the left pane, selecting New... Virtual Directory, and following the wizard. Once the new virtual directory is created, you can right-click on it and select Properties to modify its properties.

Back in Chapter 6, you created a virtual directory called Websites . This was mapped to the physical directory c:\Websites . To access this virtual directory, enter one of the following URLs from a browser, depending on whether you are on a local machine or accessing the application over a local intranet or the Internet:

 http://localhost/Websites                [local]     http://SomeComputerName/Websites         [intranet]     http://www.SomeDomainName.com/Websites   [Internet] 

Internet Explorer can determine if a URL is pointing to an intranet or an Internet address by the presence of periods in the first node. If there are any periods, then it is an Internet address. For example, both of the following URLs are Internet addresses:

 http://www.SomeDomainName.com/Websites     123.456.789.123/Websites 

This determination is important for imposing the proper security settings.




Programming ASP. NET
Programming ASP.NET 3.5
ISBN: 0596529562
EAN: 2147483647
Year: 2003
Pages: 173

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net