Chapter 1: What Does Web Programming Mean, Anyway?


This chapter will introduce you to the basic concepts of Web programming. You ll learn what the term Web programming means and why the Web pages you create are actually Web programs. I ll explain what Microsoft ASP.NET is and how it provides a framework for creating and running your Web pages (programs). In addition, I ll give you an overview of some important and unique characteristics of Web programming, such as postbacks and state management. Finally, I ll describe how Web programming differs from the browser-based programming technologies that you might be familiar with, such as applets, Flash animations, or Dynamic HTML.

Before we start, it s probably a good idea to review the concept of Web programming. People can interpret the term Web programming in several ways, so in this chapter I ll describe what it means to do server-based Web programming. I ll also give you an overview of the characteristics (some might even call them the frustrations) that are inherent in any kind of server-based Web programming.

Server As Processor, Page as Program

Let s say you type the following URL into your browser: http://www.alpineskihouse.com/. When the Web server gets the request, it reads the file extension (.html), looks for the file (main.html), reads it off its local hard disk, and sends the contents down to the browser without any further processing, as shown in Figure 1-1.

click to expand
Figure 1-1: A Web server fulfills a request for a static HTML Web page.

In this case, the Web server s role is just as expediter take request, find file, and send file.

I ll give you an analogy. Imagine the Web server as the clerk behind the counter at a fast-food restaurant that serves only prepackaged meals. In this restaurant, you tell the clerk what you want and the clerk determines on which shelf your meal is stored, retrieves it, and hands it to you in a bag. The clerk doesn t really know anything about the meals or how to prepare them. All that he or she knows is how to obtain the meal and deliver it to you.

This simple model of Web serving doesn t work for other common scenarios, though for example, using a search engine site. On a search page, you type in a term and then click Search, which sends a request to the server. When the Web server receives your search request, it fulfills the request by running a program on the server. The program performs the search and when it obtains results, it dynamically creates a page out of the results and sends the page to the browser. The model is shown in Figure 1-2.

click to expand
Figure 1-2: A Web server fulfills a request for a dynamic Web page.

Let s turn to an analogy again, with a different (and more realistic) fast-food restaurant. At this new restaurant, you place your order with a clerk. The clerk hands off the order to some other workers, who assemble your meal. When everything is done, the meal is placed in a bag and handed to you.

Notice that from your perspective, the experience in both of these hypothetical restaurants is the same. You order, you wait a short while, and then you get a bag with your meal in it. The second scenario, in which your meal is assembled for you, involves a lot of processing behind the counter, but the end result is still just a meal in a bag.

That s the nature of server-based Web programming: the page that you request is really a program that runs when you request it. (Put another way, when you request a dynamic Web page, you re really running a program on the server.) The program runs and performs whatever processing it has to search a database, get the filename of a graphic, or whatever else someone has programmed it to do constructs a Web page as its output, and sends the page to the browser.

In this book, you ll learn how to use Web Matrix to create the pages that run as programs on the Web server and dynamically generate output to send to the browser.

start sidebar
Web Servers Defined

What is a Web server, anyway? Many people think of a Web server as a computer, but technically, a Web server is a piece of software. It s a program, usually a service (permanently running background program), whose function is to monitor Web page requests and fulfill them.

In most installations, Web server software runs on a dedicated computer, also (perhaps confusingly) referred to as a server, that s permanently connected to the Internet. However, having a dedicated computer for a Web server isn t essential. Even if you re working with a stand-alone desktop computer, you can still run a Web server on your computer, which you ll be doing while working in this book. Naturally, running a Web server on a stand-alone computer is not useful for serving pages to the Internet, but it does allow you to test your Web pages.

Microsoft s Web server software is called Internet Information Services (IIS), and it s available as a component in any version of Microsoft Windows used for servers. In older versions of Windows, IIS was installed automatically, but in more recent versions you must explicitly perform the installation.

end sidebar

Where Microsoft ASP.NET Fits In

Up to now, I ve made it sound as if this abstract entity I ve called the Web server runs all the programmed Web pages on the server, but that s not quite true. When you create programmed Web pages using Web Matrix, the server processing for your pages is handled by a Microsoft technology called ASP.NET. (The ASP part comes from a Microsoft acronym for an older technology called Active Server Pages.) I ll discuss ASP.NET in greater detail in Chapter 2, but for now, think of ASP.NET as an extra piece bolted onto the Web server. When you create programmed Web pages using Web Matrix, what you re really creating are ASP.NET programs.

To get a better understanding of how ASP.NET is connected to programmed Web pages, let s go back to the high-level scenarios I was discussing earlier. Imagine that in your browser you ve typed in the URL http://www.asp.net/default.aspx. The request goes to the server, which looks at the extension (.aspx). A map on the Web server tells it that the ASPX extension is handled by ASP.NET. So the Web server hands the request off to ASP.NET and from that point, the Web server is done with the request.

ASP.NET finds the file with the ASPX extension, opens it, and executes the code in the page. If the page has output (almost always), ASP.NET creates a stream of characters containing HTML tags with that output and sends it to the browser. Got that? Request runs the program and the program produces HTML output, as shown in Figure 1-3.

click to expand
Figure 1-3: ASP.NET handles requests for .aspx files.

As for understanding ASP.NET itself, it would help to take a step back and examine some of the tasks involved in the process just described. If you were going to do every bit of the work that ASP.NET does, you would need to get the request from the Web server, find the file, open it, find the code in it, execute the code, construct a stream of characters containing HTML tags, and then, finally, put the page on the wire (as people say) to send it to the browser. Lots of work. That s one of the benefits of working with ASP.NET it does all this low-level work for you. You can concentrate on just the programming that s important to you. For example, if you build a search page, you can concentrate on getting the user s search term, running a database query with it, and putting the results into a list. ASP.NET is dealing with all the other details for you.




Microsoft ASP. NET Web Matrix Starter Kit
Microsoft ASP.NET Web Matrix Starter Kit (Bpg-Other)
ISBN: 0735618569
EAN: 2147483647
Year: 2003
Pages: 169
Authors: Mike Pope
BUY ON AMAZON

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