This is the second in a series of four tutorials that introduces ASP.NET 2.0 and Microsoft's Visual Web Developer Express IDE for building Web applications. The Visual Web Developer Express functionality we discuss is also part of the complete Visual Studio 2005. Both Visual Web Developer Express and Visual Studio 2005 are scheduled to be released in November 2005. This series of tutorials is a small part of Chapter 21, ASP.NET, Web Forms and Web Conrols, from our forthcoming book Visual Basic 2005 How to Program, 3/e. Chapter 21 is part of a four chapter sequence on XML, ADO.NET, ASP.NET and Web Services in which we discuss each of these technologies and demonstrate how to build substantial, data driven Web applications.
Part 1 of this series provided a brief introduction to ASP.NET, Web Forms and Web controls. This tutorial discusses simple HTTP transactions that enable client/server interactions on the Web. Part 3 overviews multitier application architecture.Part 4 presents a simple Web Form example, analyzes its parts, shows how it executes, and discusses how to build and deploy the Web Form. The tutorials in this series are intended for students and professionals who are already familiar with Visual Basic .NET programming. These tutorials are intended for students and professionals who are already familiar with Visual Basic .NET programming.
[Note: This series of tutorials is an excerpt (Sections 21.1-21.4) of Chapter 21, ASP.NET, Web Forms and Web Controls, from our forthcoming textbook Visual Basic 2005 How to Program, 3/e. These tutorials may refer to other chapters or sections of the book that are not included here.
Permission Information: Deitel, Harvey M. and Paul J., Visual Basic 2005 How to Program, ©2005.
Electronically reproduced by permission of Pearson Education, Inc., Upper Saddle River, New Jersey.]
Part 2: Simple HTTP Transactions
Before exploring Web application development further, a basic understanding of networking and the World Wide Web is necessary. In this section, we examine the inner workings of the Hypertext Transfer Protocol
) and discuss what occurs behind the scenes when a browser displays a Web page. HTTP specifies a set of methods
that allow clients and servers to interact and exchange information in a uniform and predictable way.
In its simplest form, a Web page is nothing more than an XHTML document. This document is a plain text file containing markup
) that describe to a Web browser how to display and format the document's information. For example, the XHTML markup
My Web Page</title>
indicates that the browser should display the text between the <title> start tag
and the </title> end tag
in the browser's title bar. XHTML documents also can contain pieces of hypertext
data (usually called hyperlinks
) that link to different pages or to other parts of the same page. When the user activates a hyperlink (usually by clicking it with the mouse), the requested Web page is loaded into the user's browser window.
Any XHTML document available for viewing over the Web has a corresponding Uniform Resource Locator (URL). Recall from Chapter 19 that a URL is an address indicating the location of an Internet resource, such as an XHTML document. The URL contains information that directs a browser to the resource that the user wishes to access. Computers that run Web server
software make such resources available. When requesting ASP.NET Web applications, the Web server is Microsoft Internet Information Services
). As we discuss shortly, it is also possible to test ASP.NET applications using the ASP.NET Development Server built into Visual Web Developer.
Let us examine the components of the URL
indicates that the resource is to be obtained using the HTTP protocol. The middle portion, www.deitel.com
, is the fully qualified hostname
of the server. The hostname is the name of the computer on which the resource resides. This computer usually is referred to as the host
, because it houses and maintains resources. The hostname www.deitel.com
is translated into an IP address
), which identifies the server in much the same way as a telephone number uniquely defines a phone line. The translation of the hostname into an IP address normally is performed by a domain name system
, a computer that maintains a database of hostnames and their corresponding IP addresses. This translation operation is called a DNS lookup
The remainder of the URL (i.e., /books/downloads.html
) specifies both the name of the requested resource (the XHTML document downloads.html
) and its path, or location (/books
), on the Web server. The path could specify the location of an actual directory on the Web server's file system. However, for security reasons, the path often specifies the location of a virtual directory
. In such systems, the server translates the virtual directory into a real location on the server (or on another computer on the server's network), thus hiding the true location of the resource. Some resources are created dynamically and do not reside anywhere on the server computer. The hostname in the URL for such a resource specifies the correct server, and the path and resource information identify the location of the resource with which to respond to the client's request.
When given a URL, a Web browser performs a simple HTTP transaction to retrieve and display the Web page found at that address. Figure 21.1
illustrates the transaction in detail. This transaction consists of interaction between the Web browser (the client side) and the Web-server application (the server side).
Fig. 21.1 Client interacting with Web server. Step 1: The GET request.
In Fig. 21.1
, the Web browser sends an HTTP request to the server. The request (in its simplest form) is
GET /books/downloads.html HTTP/1.1
The word GET
is an HTTP method indicating that the client wishes to obtain a resource from the server. The remainder of the request provides the path name of the resource (an XHTML document) and the protocol's name and version number (HTTP/1.1
Any server that understands HTTP (version 1.1) can translate this request and respond appropriately. Figure 21.2
depicts the results of a successful request. The server first responds by sending a line of text that indicates the HTTP version, followed by a numeric code and phrase describing the status of the transaction. For example,
indicates success, whereas
informs the client that the Web server could not locate the requested resource.
Fig. 21.2 Client interacting with Web server. Step 2: The HTTP response.
The server then sends one or more HTTP headers,
which provide additional information about the data that will be sent. In this case, the server is sending an XHTML text document, so the HTTP header for this example reads:
The information provided in this header specifies the Multipurpose Internet Mail Extensions
) type of the content that the server is transmitting to the browser. MIME is an Internet standard that specifies the way in which certain data must be formatted so that programs can interpret the data correctly. For example, the MIME type text/plain
indicates that the sent information is text that can be displayed directly, without any interpretation of the content as XHTML markup. Similarly, the MIME type image/jpeg
indicates that the content is a JPEG image. When the browser receives this MIME type, it attempts to display the image.
The header or set of headers is followed by a blank line, which indicates to the client that the server has finished sending HTTP headers. The server then sends the contents of the requested XHTML document (downloads.html
). The server terminates the connection when the resource transfer is complete. At this point, the client-side browser parses the XHTML markup it has received and renders
(or displays) the results.
Tutorials in This Series:
ASP.NET Tutorial Part 1: Introduction to ASP.NET
ASP.NET Tutorial Part 2: Simple HTTP Transactions (You are here.)
ASP.NET Tutorial Part 3: Multitier Application Architecture
ASP.NET Tutorial Part 4: Creating and Running a Simple Web Form Example