Export (0) Print
Expand All

ASP.NET Intrinsic Objects

.NET Framework 1.1

Many features of ASP.NET will be familiar to you if you have used previous versions of ASP. Although the object-oriented design and underlying code of ASP.NET is radically different from ASP, many of the most commonly used keywords and operators in ASP remain in ASP.NET. Familiar intrinsic objects such as Request, Response, Server, Application, and Session are part of ASP.NET and are used in much the same way as they were in ASP. However, in ASP.NET these objects are defined in new classes in the System.Web namespace. For example, these intrinsic objects are now properties of the System.Web.HttpContext class but because the objects are automatically created by ASP.NET when a new request for a Web resource is received and a new context is created, you can use them directly without having to instantiate new objects.

Looking at one specific case, the intrinsic Request object is defined as a property of the HttpContext class. Because the HttpContext.Request property is of type HttpRequest, the ASP.NET intrinsic Request object has all the properties and methods of HttpRequest automatically available to it. Thus to get the length, in bytes, of the content sent by the client browser, you only need to specify the Request.ContentLength.

Some ASP.NET objects function exactly as they did in ASP. Response.Write("some output") is an example of an object that performs exactly the same as in previous versions of ASP.

The values returned by some ASP.NET methods are different from those in ASP and in some cases must be coded differently. For example, Request.QueryString, Request.Form, and Request.ServerVariables were simple collections in ASP but are of type NameValueCollection in ASP.NET. A NameValueCollection can be used in much the same way as a simple collection in ASP but the NameValueCollection class contains many more members than are contained in a simple collection. You can still extract one item by name from a NameValueCollection in the same way you would from a simple collection in ASP, as shown in the following example:

svrname=Request.ServerVariables("SERVER_NAME")

For an example of how to extract all the values from a NameValueCollection, see the code sample at HttpRequest.ServerVariables.

Show:
© 2014 Microsoft