The Evolution of ASP.NET
We covered the essentials of Internet connectivity and some development strategies in previous chapters. To fully understand the impact of ASP.NET, you need a sense of the evolution of the Web in the past few years. The Web of 1993 was very different from the Web of today. In the earliest days, most Web sites were simply hyperlinked files and graphics. These days, the Web represents a fully capable interactive computing platform.As people began to get tired of looking at each other's photo albums over the Web, HTML began to develop into a markup language that could describe controls and interactive user interface elements, not just simple formatting. This paved the way for dynamic content—Web site content that changed at run time based on factors such as user selections, information in a database, and so on.The first dynamic Web sites were written using the Common Gateway Interface (CGI). CGI launches a new process in response to each incoming HTTP request. The process emits some customized HTML based on the request. CGI was fairly effective, but one major drawback was the fact that each incoming HTTP request had to beget a new process, creating a huge burden on the server. (Creating a new process for each request is pretty expensive.)
To make things more efficient for Microsoft Windows–based Web servers, Microsoft implemented a programming interface named the Internet Server Application Programming Interface (ISAPI), which you saw briefly in Chapter 30. As learned in that chapter, IIS fires up a new instance of an ISAPI DLL that's been mapped to a specific file extension. The DLL renders specific HTML based on the incoming request. Unfortunately, when ISAPI DLLs were introduced, the only effective way to write them was using C++. Microsoft introduced Active Server Pages (ASP) to help developers develop Web pages more quickly.Classic ASP is driven by a single DLL named Asp.dll. Asp.dll reads ASP files that combine script and HTML and renders markup language back to the client. The code within the scripting blocks controls the content coming from an ASP page. The script blocks usually drive COM objects that perform such operations as accessing databases and processing transactions. The ASP object model provides easily-accessed objects representing HTTP requests and responses. For example, to emit the string Hello World to the browser connected to your server, you just call Response.Write("Hello World") from within a server-side script block.When ASP came out in the late 1990s, it made Web-site development available to non-C++ developers. No longer were ISAPI DLLs the only way to get content out to a client browser. However, classic ASP started showing some warts after developers began exercising it extensively. First, many ASP pages ended up being very disorganized. ASP let you wantonly mix user interface code and execution code in the same page, so many ASP pages end up looking like spaghetti code.Second, the ASP object model is fairly unstructured. ASP has numerous intrinsic, or global, objects that seem to come out of nowhere. For example, when you write script code to generate the content of an HTTP request, the Response object includes the methods for writing text out to the client. Unfortunately, ASP doesn't support state management very well. These are just a couple of the issues faced by ASP developers—there are others. For example, classic ASP code tends to mix user interface code with executable code, making the page hard to maintain. If you want to run an ASP Web site over a Web farm, you need to manage application state between each of the servers yourself. Managing the state of your application's user interface involves lots of mundane code to check the state of the user interface between posts. ASP.NET has evolved to solve some of the most common problems facing Web site developers.
Most of the improvement ASP.NET makes over classic ASP is evolutionary. For example, ASP.NET includes similarly named objects (Response, Request, and Server) for managing requests. ASP.NET provides an architecture for these objects—they don't come out of nowhere. (ASP intrinsic objects are attached to a thread's context.) The syntactic similarity between ASP and ASP.NET means that many ASP pages can easily be run as ASP.NET pages if you rename them using the ASPX extension. (ASP.NET installs several file types in IIS (ASPX, ASMX, ASCX, and ASHX) that redirect processing to ASP.NET.However, ASP.NET is more than a simple evolution of classic ASP. Whereas classic ASP leverages many features from IIS, ASP.NET generally uses IIS only to intercept the HTTP request. Features generally provided by IIS and the Web Application Manager (WAM), including such features as process isolation and security, are provided by the ASP.NET infrastructure and by classes within the common language runtime.Rather than being interpreted (as classic ASP applications are), ASP.NET applications are compiled into common language runtime assemblies. Because ASP.NET applications are compiled, you can use any .NET language to write the executable part of a page. Also, because ASP.NET applications are compiled for the runtime, component integration within a .NET application is much easier than with classic ASP applications (which use COM as the component integration technology).ASP.NET also includes some features completely absent from classic ASP, including server-side controls, data binding, and Web services. Server-side controls vastly simplify Web user interface programming by handling the mundane details of user interface state management between postbacks. Data binding also simplifies user interface programming by managing the details of rendering such collection-oriented user interface elements as combo boxes, list boxes, and grids. Finally, ASP.NET represents a framework for intercepting and mapping SOAP requests to individual methods written into your application.