For those new to ASP.NET, (like me) this is a good explanation of the process and hopefully demystifies the delays.
Here is the step-by-step process:
1. The compilation of C# code into a DLL
An ASP.NET project's C# code, including the "code-behind" files (e.g., MyPage.aspx.cs), is compiled into a Dynamic-Link Library (.dll). This compilation typically happens during development or deployment in a "Web Application Project" model.
- The C# code contains the application's core logic, event handlers for page elements, and methods for interacting with data.
- This
.dllfile is placed in thebindirectory of the web application.
2. The user's browser requests an .aspx page
When a user requests an .aspx page, such as http://www.example.com/MyPage.aspx, the web server's ASP.NET runtime intercepts the request.
3. The ASP.NET runtime compiles the .aspx page
The ASP.NET runtime is a key component of this process. If it's the first time the page has been requested since the application was deployed or changed, the runtime performs the following steps:
- It reads the
.aspxfile, which contains both static HTML markup and server-side elements like<asp:Label>or<% %>tags. - It dynamically generates a C# class that represents the entire page. This class is a "partial class" and is combined with the C# code from the
.aspx.csfile. - This dynamically generated C# class, along with the code-behind class from the compiled
.dll, is then compiled by the runtime into another temporary assembly (DLL). - This newly created
.dllis stored in a temporary ASP.NET files folder on the server and is used for all subsequent requests to that page until the.aspxfile is modified.
4. The Page class and rendering
The generated .dll contains a class that inherits from the System.Web.UI.Page class. The ASP.NET framework creates an instance of this Page class and runs it through the page lifecycle.
- During this lifecycle, the
Pageobject's properties and methods (which are defined in both the.aspxmarkup and the.aspx.cscode-behind) are executed. - The server-side code from your
.dllis called to perform actions like populating data into controls or handling button clicks.
5. HTML is rendered and sent to the client
Finally, as part of the page lifecycle, the Page class renders its output.
- All server-side controls are processed and converted into standard HTML markup, JavaScript, and CSS.
- This final, rendered HTML output is then sent back to the user's browser.
- From the browser's perspective, it receives only standard HTML, not the original
.aspxcode or the C# source. This is why you lose all dynamic elements if you simply save the page source, because you are only saving the static output.