Home > Articles > Programming > Windows Programming

  • Print
  • + Share This
This chapter is from the book

Running the Code Listings

You will, of course, want to run and experiment with the samples that we provide in this book. The following sections explain how to do so.

NOTE

The code listings in this book have been triple-checked to be error free. However, if a bug happens to creep into a code listing, let us know about it, and it will be fixed and ready for downloading on the book's Web site, at http://www.samspublishing.com.

Running the Code Listings with a Web Browser

You can run almost all the samples in this book by simply using your favorite Web browser. You don't need to use the Visual Basic compiler or Visual Studio unless the section gives explicit instructions to do so. Most of the samples rely on ASP.NET, which will compile each listing automatically when it's first requested by a browser.

NOTE

Of course, future lessons will explain how to use the Visual Basic compiler directly if you choose to do so, and today's section titled "Running the Samples Using Visual Studio" will show you how to use Visual Studio for this book's listings.

Let's take a dry run using an extremely simple ASP.NET page to see how you can use a Web browser to run the code listing.

Using Internet Services Manager

Being an effective Internet developer means being familiar with the Internet Services Manager (ISM), among other things. ISM is an administrative program that allows you to configure the IIS Web server program. By using ISM, you can add and remove virtual directories and change security settings. ISM is essential for developing any kind of Web application using IIS, and you will use it frequently in subsequent lessons. When IIS is installed onto a computer, ISM is installed along with it automatically. Here's how to run ISM:

  1. In the Windows Control Panel, double-click the Administrative Tools icon.

  2. In the Administrative Tools dialog, double-click the Internet Services Manager icon. If the icon doesn't appear in the window, IIS hasn't been installed properly on your computer.

Finding the Root Virtual Directory

Now that you've started the Internet Services Manager application, you need to find the root virtual directory for IIS:

  1. Expand the tree view on the left. You should see three nodes: Default FTP Site, Default Web Site, and Default SMTP Virtual Server.

  2. Right-click the Default Web Site Node and select Properties.

  3. In the Default Web Site Properties dialog, select the Home Directory tab. The directory in the Local Path text box corresponds to the IIS root virtual directory. Normally, this path is C:\inetpub\wwwroot, but yours may vary. Make note of this folder's name.

Creating and Running an ASP.NET Page at the Root

Create a file named HelloWorld.aspx with a text editor such as Notepad, type the contents of Listing 1.3, and save the file into the directory that corresponds to the IIS root virtual directory. (You can also download this listing from the book's Web site.)

Listing 1.3 HelloWorld.aspx: A Trivial ASP.NET Page

<%@ Page Language="VB" %>
<html>
<body>
<% Response.Write("Hello World from asp.net") %>
</body>

Now you can view the file by using your favorite Web browser. To do so, use the name localhost for your computer. The URL to access Listing 1.3 is http://localhost/HelloWorld.aspx. In addition to using the name localhost, you can use the numerical address 127.0.0.1. You can run Listing 1.3 by using the URL http://127.0.0.1/HelloWorld.aspx.

Tomorrow's lesson will explain how to create new virtual directories. By creating new virtual directories, you can make a new project for each new day's code examples.

Running the Samples Using Visual Studio

When working with samples in Visual Studio, you will need to make some small changes to the single-file sample programs, and you will spend a good amount of time deleting template code that Visual Studio generates while trying to be helpful. We suggest that you take the following approach for each book sample if you want to convert it into a Visual Studio project:

  1. Open Visual Studio and start a new Empty Web Application project, assigning it a descriptive name.

  2. Add a new Web Configuration file to the project. To do so, choose Add New Item from the Project menu. In the resulting dialog box, select Web Configuration File and click Open.

  3. Add a new Web form to the project, assigning it a descriptive name. To do so, choose Add New Web Form from the Project menu, type the descriptive name, and click Open.

  4. Replace the entire contents of the Web form with the contents of the sample.

  5. The Web form you created will appear in the Solution Explorer window on the right. Right-click the Web form in the Solution Explorer and select the Set as Start Page option.

  6. Run the listing by pressing F5.

This six-step process can become tedious. As a result, we have created installation programs that will create Visual Studio projects containing all the code listings for each lesson. These installation programs are available on the book's Web site at http://www.samspublishing.com.

  • + Share This
  • 🔖 Save To Your Account