Article

ASP.NET 2.0: A Getting Started Guide

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Next

Installing the Web Server

Installing Internet Information Services (IIS)

IIS comes with most versions of server-capable Windows operating systems--including Windows 2000 Professional, Server, and Advanced Server; Windows XP Professional; Windows XP Media Center Edition; and Windows Server 2003--but it's not installed automatically in all versions, which is why it may not be present on your computer. IIS isn't available for Home editions of these operating systems, such as Windows XP Home Edition. If you run this, you'll need to rely on Cassini, which we discuss below.

To see whether you have IIS installed and running, simply locate your Administrative Tools folder (sometimes it's a menu option; sometimes it's a folder in the Control Panel (To see this folder, you'll need to view the Control Panel in "classic view.") and check whether or not it contains a shortcut to Internet Information Services. If the shortcut isn't visible, then it's not installed. To install IIS, simply follow these steps:

  1. In the Control Panel, select Add or Remove Programs.

  2. Choose Add/Remove Windows Components. The list of components will become visible within a few seconds.

  3. In the list of components, check Internet Information Services (IIS), as shown in Figure 1.2. The default installation options are enough for ASP.NET development, but you may want to click Details... to view the extra options you could add.

  4. Click Next. Windows may prompt you to insert the Windows CD.

1556_0107_iis_install
Figure 1.2. Installing IIS

Add Administrative Tools to the Start Menu

Here's how to add Administrative Tools to the Windows XP Start menu:

  1. Right-click on the Start button and select Properties to bring up the Taskbar and Start Menu Properties dialog.

  2. Click the Customize... button to bring up the Customize Start Menu dialog.

  3. If you're using the classic Start menu, check Display Administrative Tools, then click OK.

  4. If you're using the Windows XP-style Start menu, click the Advanced tab, scroll through the Start menu items list until you get to System Administrative Tools, and select from Display on the All Programs menu or Display in the All Programs menu and the Start menu.

Once IIS is installed, close the Add or Remove Programs dialog. To check that IIS has installed correctly, see if you can find the Internet Information Services short cut in Administrative Tools. If you can, IIS is installed. Open the link to make first contact with the IIS management console, which is shown in Figure 1.3. In the left pane, you'll initially see the name of your computer, whose nodes you can expand.

1556_0114_iis_tool
Figure 1.3. The IIS administration tool

You can close this tool for now; you'll meet it again later.

You are now ready to host web applications. Although we won't cover the configuration of IIS for external use, we will show you how to configure IIS to support local development of ASP.NET applications in order that they may be uploaded to your external web hosting provider later.

Installing Cassini

If you're unable to install IIS, you'll need to download and install Cassini:

  1. Go to the Cassini download page.

  2. Download the Cassini installer executable (cassini.exe).

  3. Run cassini.exe and follow the steps presented by the installer, accepting the default options.

If the process went to plan, everything you need to run Cassini can be found in the folder C:\Cassini. Double-click CassiniWebServer.exe in that folder to start its management console, which is shown in Figure 1.4.

1556_fig-cassini
Figure 1.4. The Cassini management console

We'll need to do some more work to get Cassini up and running properly, but we'll need to install the .NET Framework and the Software Development Kit first.

Installing the .NET Framework and the SDK

To begin creating ASP.NET applications, you'll need to install the .NET Framework and the Software Development Kit (SDK). The .NET Framework includes the files necessary to run and view ASP.NET pages, while the SDK includes samples, documentation, and a variety of free tools.

Installing the .NET Framework

The best method of acquiring the .NET Framework is to download and install it directly from the Web. Note that it is also delivered through Windows Update, so you may already have it installed on your system. To check, open the folder C:\WINDOWS\Microsoft.NET\Framework (if your copy of Windows is installed somewhere other than C:\WINDOWS, change this path accordingly). If this folder doesn't exist, you definitely don't have the .NET Framework installed. If it does exist, you should find inside it at least one folder with a name like v1.1.4322. Each of these kinds of folders holds a different version of the .NET Framework you have installed. If at least one of these folders' names doesn't start with v2 or higher, you'll need to install the latest version of the .NET Framework.

To install the latest version of the .NET Framework, simply follow the steps outlined below:

  1. Go to the ASP.NET support site and click the Download the .NET Framework link.

  2. Under the .NET Framework Version 2.0 Redistributable Package heading, click the appropriate download link for your hardware. Remember, we'll install the redistributable package first, then the SDK. The link will advance you to a download page.

  3. Choose the language and version of the installation you want, and click Download.

  4. Save the file to a local directory. After the download is complete, double-click the executable to begin the installation.

  5. Follow the steps presented by the wizard until installation completes.

Installing the SDK

Now that you've installed the redistributable package, you need to install the Software Development Kit (SDK):

  1. Go back to the ASP.NET support site and follow the Download the .NET Framework link again.

  2. This time, click the appropriate download link under the .NET Framework Version 2.0 Software Development Kit heading. The link will advance you to a download page.

  3. Choose the language version of the installation you want to use and click Download, as you did to download the redistributable package.

  4. When prompted to do so, save the file to a local directory.

  5. After the download is complete, double-click the executable to begin the installation. Before you do so, I strongly recommend that you close all other programs to ensure the install proceeds smoothly.

  6. Follow the steps outlined by the .NET Setup Wizard until installation completes. When asked for setup options, it's safe to use the default values.

The SDK will take slightly longer to install than the framework.

A Big Download!
The .NET Framework SDK weighs in at about 350MB, so it will probably take a while to download.

Configuring the Web Server

Configuring IIS

After installing the .NET Framework and the SDK manually, you will need to configure IIS to make it aware of ASP.NET. To do this, you need to follow a few simple steps:

Open the command prompt by selecting Start > All Programs > Microsoft .NET Frameworks SDK v2.0 > SDK Command Prompt.

Type the following command to install ASP.NET:

C:\Program Files\...\SDK\v2.0>aspnet_regiis.exe -i  
Start installing ASP.NET (2.0.50727).  
.........  
Finished installing ASP.NET (2.0.50727).

Once ASP.NET is installed, close the command prompt and check again to confirm that ASP.NET installed correctly.

Running aspnet_regiis.exe
Depending on the circumstances, ASP.NET may already have been installed for you, but running aspnet_regiis.exe can't hurt. Also, remember that you need to run this utility again in case you reinstall IIS.

Configuring Cassini

If you've installed Cassini, you'll need to get under the hood of the .NET Framework to coerce Cassini into working as it should.

Open the command prompt by selecting Start > All Programs > Microsoft .NET Frameworks SDK v2.0 > SDK Command Prompt.

Enter the following command at the prompt:

C:\Program Files\...\SDK\v2.0>gacutil /i C:\Cassini\Cassini.dll  
Microsoft (R) .NET Global Assembly Cache Utility. Version 2.0...  
Copyright (c) Microsoft Corporation.  All rights reserved.  
 
Assembly successfully added to the cache

Cassini is now ready to go.

Where do I Put my Files?

IIS Recommended
From here on in, the instructions we provide will be centered around IIS, as Cassini isn't suitable for production environments. Many of the concepts we'll discuss do not apply to Cassini, as it's much simpler and lacks many of IIS's features. Where needed, Cassini instructions will be given, but IIS will receive the bulk of the discussion.

Now that you have ASP.NET up and running, let's find out where the files for your web applications are kept on the computer. You can readily set IIS to look for web applications in any folder, including the My Documents folder, or even a network share. By default, IIS maps the C:\Inetpub\wwwroot folder of your disk to your web site's root directory, which is generally considered a good repository for storing and managing your web applications.

If you open this wwwroot folder in Windows Explorer, and compare its contents with the files that appear in the Default Web Site in the IIS administration tool, as shown in Figure 1.5, you'll notice that the files and folders are the same (some extra items will be listed in IIS; we'll look at these shortly). You need to use the IIS administration tool to set up the behavior of these files and folders under IIS. We'll see more on this soon.

1556_fig-foldersiis
Figure 1.5. Folders inside wwwroot also appear inside IIS

Using localhost

By putting your files within C:\Inetpub\wwwroot, you give your web server access to them. If you've been developing web pages for a long time, habit may drive you to open files directly in your browser by double-clicking on the HTML files. However, because ASP.NET is a server-side language, your web server needs to have a crack at the file before it's sent to your browser for display. If the server doesn't get this opportunity, the ASP.NET code won't be converted into HTML that your browser can understand. For this reason, ASP.NET files can't be opened directly from the disk using Windows Explorer.

Your local web server can be accessed through a special web address that indicates the current computer: http://localhost/. If you try this now, IIS will open up a default help page (although this behavior will vary depending on the settings of your Windows installation; for example, if you get an error instead of the default help page, don't worry).

What you need to keep in mind, though, is that the address you'll use to access local web applications will always start with http://localhost/, and that, by default, this root address points to the folder on your disk.

To see this in practice, create a new file named index.htm inside C:\Inetpub\wwwroot, with the following contents (note that all of the code and images used in this book are available for download from sitepoint.com. See the Preface for more information):

Example 1.1. index.htm  
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
<html>  
 <head>  
   <title>Simple HTML Page</title>  
 </head>  
 <body>  
   <P>This is a simple HTML page.  
 </body>  
</html>

Now, load this page through http://localhost/index.htm, as shown in Figure 1.6.

1556_0125_first
Figure 1.6. Testing IIS

Experiencing an Error?
If the page doesn't load as illustrated in Figure 1.6, your IIS installation has problems. You might want to double-check that you correctly followed the steps for installing it, and re-check the IIS configuration procedure.

This localhost name is equivalent to the so-called loopback IP address, 127.0.0.1, so you can get the same results by entering http://127.0.0.1/index.htm into your browser. If you know them, you can also use the name or IP address of your machine to the same end.

Note that if you do try any of these equivalents, a dialog will appear before the page is opened, to ask you for your network credentials. This occurs because you're no longer using your local authentication, which is implicit with localhost.

Stopping and Starting IIS
Now that we have IIS up and running, and ASP.NET installed, let's look at how you can start, stop, and restart IIS if the need arises. For the most part, you'll always want to have IIS running; however, if you want to shut it down temporarily for any reason (such as security concerns), you can. Also, some external programs may stop IIS upon launch because of potential security vulnerabilities, so you'll need to start it again yourself. If you want to stop IIS when it's not being used, simply open the Internet Information Services management console, right-click on Default Web Site and select Stop. Alternatively, after selecting Default Web Site, you can use the Stop, Pause, and Play icons from the toolbar.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links