DekGenius.com
[ Team LiB ] Previous Section Next Section

Chapter 23. The System.Web Namespace

The System.Web namespace contains some of the fundamental ingredients for ASP.NET applications. These ingredients include the classes used for the original built-in ASP objects (Request, Response, Application, and Server), as well as classes for managing cookies, configuring page caching, implementing tracing, and retrieving information about the web server and client browser. Aside from the classes required for web services and the Web Forms user interface, the System.Web namespace contains the heart of ASP.NET's functionality. Figure 23-1 and Figure 23-2 show the types in this namespace.

One confusing aspect about the System.Web namespace is Microsoft's "all roads lead to Rome" approach to backward compatibility. For example, the HttpRequest class can be accessed on a Web Form through the Page class (Page.Request), the HttpContext class (Page.Context.Request), and the HttpApplication class (Page.Context.ApplicationInstance.Request). In all cases, the reference is pointing to the same object. Essentially, the HttpContext class encapsulates the fundamental types that relate to an HTTP request. The HttpContext object is made available to all IHttpModule and IHttpHandler instances (which includes HttpApplication, System.Web.UI.Page, and System.Web.UI.UserControl), and some of its properties are "magically" copied into these classes for convenience and backward compatibility. When you use the built-in Request object on a Web Forms page, for example, you use the Request property from the Page class. Generally, using the Page properties is the easiest and least expensive way to access the built-in objects.

Due to backward compatibility, some class names don't match the name of the corresponding built-in object. For example, the Application object is an instance of the HttpApplicationState class, not the HttpApplication class. Similarly, the built-in Response.Cache object references an instance of the HttpCachePolicy class, while the built-in Cache object references the System.Web.Caching.Cache class.

Figure 23-1. Fundamental types from System.Web
figs/anet2_2301.gif
Figure 23-2. More System.Web types, including collections and exceptions
figs/anet2_2302.gif
    [ Team LiB ] Previous Section Next Section