ASP.NET 2.0 Introduction

The following post will give an introduction to some of the main characteristics provided by ASP.NET 2.0 when developing WebApplications.

Component Model

It is important to remark that ASP.NET 2.0 uses a component model that maps all elements required by the WebSite into server side classes.

That is why pages are transformed by the ASP.NET runtime into classes that inherit from page. To transform page elements into their server side “pairs” the runat attribute must be added to the element description.

The great advantage that comes with this is that by “transforming” each page element¬† page into an object, you can use the entire .NET Framework class libraries, and usual object oriented programming syntax can be used to modify it.

For example:

<!-- Page Layout -->
<body runat="server" id="TheBody">

So in your code you could write the following to set the Background color in runtime:

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        TheBody.Style[HtmlTextWriterStyle.BackgroundColor] = "#006600";
    }
}

Provider Model

The provider model is based on the Strategy Pattern, which allows the application to select the best suitable algorithm for a specific behavior. This model enables some base functionality to be easily changed by repeating a similar approach each time this is done.

The model is composed by base classes which define the methods that the customizable implementations ought to implement, thus serving as a guidance for developers. Parameters for initialization and storage for each of the providers are defined in the Configuration file.

HTTP Runtime Environment

The following diagram shows the overview of the HTTP Runtime Environment:

image

Basically when an ASP.NET request is “listened” it is directed to an application pool within which a Worker Process is executed (w3wp.EXE in ASP.NET 2.0 with IIS 6.0). For each request a different worker thread is executed. The threads start the HTTP Runtime Pipeline which allows the modifications of requests (either by HTTP Applications/Modules) before the HTTP handler is executed on the request. Once it is updated it goes back to the worker thread.

The HTTP Context is obtained before any changes are done to the request. Since it is “raw” you can run any code by the request prior its modification:

void ShowName()
{
    HttpContext currentcontext = HttpContext.Current;
    string user = currentcontext.User.Identity.Name;
    currentcontext.Response.Write("Hi" + user);
}



Leave a Reply