An ASP.NET Web Application in Action - How an ASP.NET application is compiled and run
(Page 4 of 5 )
The diagram in figure 1-12 shows what actually happens behind the scenes when a user requests a page of an ASP.NET 3.5 application. In step 1, the ASP.NET runtime reads the aspx file for the requested web page and generates a class and a partial class. The partial class contains the declarations for the form and the controls it contains and is given the same name as the partial class that’s defined by the code-behind file for the page (Order in this example). In step 2, these partial classes are compiled to create a single class that provides all of the event-handling code for the page. The result is stored in a single assembly (dll file).
The class that’s generated by the ASP.NET runtime contains the code that actually creates the ASP.NET page. This class gets its name from the aspx file for the web page plus _aspx, so its name is Order_aspx in this example. In step 3, this class is compiled and stored in another assembly. Because this class inherits the Order class, an object that is instantiated from the Order_aspx class will contain the code that creates the page, as well as the event-handling code provided by the Order class.
In step 4, after the page classes are compiled, the ASP.NET runtime calls the Visual Basic compiler to compile any class files that are in the application’s App_Code folder. For the Shopping Cart application, this means that the CartItem and Product classes are compiled and the result is saved in a single assembly.
After all the files are compiled into assemblies, ASP.NET creates an instance of the page and raises the appropriate events. Then, the events are processed by the event handlers for the page and the HTML for the page is rendered. To complete the round trip, the HTML document for the page is passed back to the web server and on to the user’s browser.
Please note that the first four steps are done only the first time an aspx page is accessed. That’s because ASP.NET caches the assemblies that are created by these steps. Then, when the page is accessed again, the saved assemblies are reused, so the application doesn’t have to be recompiled. However, ASP.NET does compare the time stamps on the source files with the time stamps on the dll files. If any of the source files have been modified since they were last compiled, ASP.NET automatically recompiles them.
How an ASP.NET application is compiled

What happens when an ASP.NET page is requested
The ASP.NET runtime processes the .aspx file and generates a partial class (Order) that contains the declarations for the form and its controls, and a class (Order_aspx) that contains the code that will initialize the form, instantiate the controls, and generate the HTML for the web page.
The Visual Basic compiler compiles the partial class that contains the control declarations with the partial class defined by the code-behind file for the form into an assembly (.dll) that provides the event-handling code for the requested page.
The Visual Basic compiler compiles the Order_aspx class, which inherits the first compiled class (Order), and saves the result as an assembly that’s executed when the page is requested.
If necessary, the Visual Basic compiler compiles any other class files that are stored in the application’s App_Code folder. These classes are saved in a single assembly.
ASP.NET creates an instance of the page from the page’s final assembly. Then, ASP.NET raises the appropriate events, which are processed by the event handlers for the page, and the page generates the HTML that’s passed back to IIS for the response.
Description
The first four steps of this process are done only the first time the aspx page is requested. After that, the page is processed directly from the compiled assemblies.
For the Default page, the name of the code-behind class is _Default.
Figure 1-12 How an ASP.NET 3.5 application is compiled and run
Next: Perspective >>
More ASP.NET Articles
More By Murach Publishing
|
This article is an excerpt from chapter one of Murach's ASP.NET 3.5 Web Programming with VB 2008, written by Anne Boehm (Murach, 2008; ISBN: 1890774472). Check it out today at your favorite bookstore. Buy this book now.
|
|