Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Build Your Own ASP.NET 2.0 Web Site Using CSharp And VB (2006) [eng]-1.pdf
Скачиваний:
143
Добавлен:
16.08.2013
Размер:
15.69 Mб
Скачать

Configuring the Web Server

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:

1.Open the command prompt by selecting Start > All Programs > Microsoft

.NET Frameworks SDK v2.0 > SDK Command Prompt.

2.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).

11

Chapter 1: Introducing ASP.NET and the .NET Platform

3.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.

1.Open the command prompt by selecting Start > All Programs > Microsoft

.NET Frameworks SDK v2.0 > SDK Command Prompt.

2.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.

12

Configuring the Web Server

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.

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

13

Chapter 1: Introducing ASP.NET and the .NET Platform

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 contents6:

File: 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.

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.

6 All of the code and images used in this book are available for download from sitepoint.com. See the Preface for more information.

14