Chapter 16. The HttpRequest Class

The HttpRequest class is ASP.NET’s replacement for ASP’s Request intrinsic object. Because the HttpRequest class instance for a given ASP.NET page is exposed as the Request property of the Page class (from which all pages are derived), you can code to the HttpRequest class just as you did in ASP. Thus, your existing ASP code will be that much easier to migrate.

The HttpRequest class is used to access information related to a particular HTTP request made by a web client. The HttpRequest class provides access to this information through its properties, collections, and methods.

Each HTTP request from a client consists of an HTTP header and, optionally, a body. The header and body are separated by a blank line. The code following shows a typical HTTP request (without a body):

GET /ASPdotNET_iaN/Chapter_16/showHTTP.aspx HTTP/1.0
Connection: Keep-Alive
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Charset: iso-8859-1,*,utf-8
Accept-Encoding: gzip
Accept-Language: en
Host: localhost
User-Agent: Mozilla/4.08 [en] (WinNT; U ;Nav)

The first line of the HTTP header contains the request type, followed by a space, followed by the requested URL (URI), another space, and the HTTP version number. In the previous example, the request type is GET, the URL is /ASPdotNET_iaN/Chapter_16/showHTTP.aspx (this URL is relative to the server or domain name), and the HTTP version is 1.0.

Get ASP.NET in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.