ASP.NET Intrinsic ObjectsASP.NET provides intrinsic objects to enable low-level access to the Web application framework. These objects allow you to work directly with the underlying HTTP streams and server, session, and application objects. The intrinsic objects can be accessed in a Web form through the properties of the Page class. Table 4.1 lists the important intrinsic objects and the properties of the Page class to which they are mapped. Table 4.1. Intrinsic Objects and Their Mappings to the Page Class Properties
The HttpRequest ObjectThe HttpRequest object represents the incoming request from the client to the Web server. The request from the client can come in two ways GET or POST . GET attaches the data with the URL, whereas POST embeds the data within the HTTP request body.
The
HttpRequest
intrinsic object can be accessed by the
Request
property of the
Page
class. Tables 4.2
and 4.3 list the properties and
Table 4.2. Properties of the HttpRequest Class
Table 4.3. Methods of the HttpRequest Class
The following code segment displays the header information sent by the client to the server:
// Display the request header
System.Collections.Specialized.NameValueCollection
nvcHeaders = Request.Headers;
String[] astrKeys = nvcHeaders.AllKeys;
// Iterate through all header keys and display their values
foreach (String strKey in astrKeys)
{
Response.Write(strKey + ": " + nvcHeaders[strKey].ToString());
Response.Write("<br>");
}
Some properties of the
HttpRequest
objectsuch as
Form
,
QueryString
,
Headers
, and so
onreturn a
NameValueCollection
containing a collection of key-value pairs of their contents. The
previous code segment
The HttpResponse ObjectThe HttpResponse object represents the response sent back to the client from the Web server. It contains properties and methods that provide direct access to the response stream and enable you to set its behavior and operations. The Response property of the Page class provides access to the HttpResponse object. Tables 4.4 and 4.5 list the properties and methods of the HttpResponse class, respectively. Table 4.4. Properties of the HttpResponse Class
Table 4.5. Methods of the HttpResponse Class
The following example shows the use of the
HttpResponse
object methods and properties to create a response that displays
the File Download dialog box and allows the
The HttpServerUtility Object
The
HttpServerUtility
object contains utility methods
and properties to work with the Web server. It also contains
methods to enable HTML/URL encoding and decoding, execute or
transfer to an ASPX page, create COM
Table 4.6. Properties of the HttpServerUtility Class
Table 4.7. Methods of the HttpServerUtility Class
|