Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [90]

By Root 5290 0
resources with an .aspx extension.

Resource Mappings


IIS stores the list of recognized resources in the IIS metabase. Depending on the version of IIS you are using, the metabase might be a hidden component or a plain configuration file that an administrator can freely edit by hand. Regardless of the internal implementation, the IIS manager tool provides a user interface to edit the content of the metabase.

Upon installation, ASP.NET modifies the IIS metabase to make sure that aspnet_isapi.dll can handle some typical ASP.NET resources. Table 5-1 lists some of these resources.

Table 5-1. IIS Application Mappings for aspnet_isapi.dll

Extension

Resource Type

.asax

ASP.NET application files. Note, though, that any .asax file other than global.asax is ignored. The mapping is there only to ensure that global.asax can’t be requested directly.

.ascx

ASP.NET user control files.

.ashx

HTTP handlers—namely, managed modules that interact with the low-level request and response services of IIS.

.asmx

Files that represent the endpoint of old-fashioned .NET Web services.

.aspx

Files that represent ASP.NET pages.

.axd

Extension that identifies internal HTTP handlers used to implement system features such as application-level tracing ( trace.axd) or script injection (webresource.axd).

.svc

Files that represent the endpoint of a Windows Communication Foundation (WCF) service.

In addition, the aspnet_isapi.dll extension handles other typical Microsoft Visual Studio extensions such as .cs, .csproj, .vb, .vbproj, .config, and .resx.

As mentioned in Chapter 2, the exact behavior of the ASP.NET ISAPI extension depends on the process model selected for the application—integrated pipeline (the default in IIS 7 and superior) or classic pipeline. Regardless of the model, at the end of the processing pipeline the originally requested URL that refers to an .aspx resource is mapped to, and served through, an instance of a class that represents an ASP.NET Web Forms page. The base class is the System.Web.UI.Page class.

Representing the Requested Page


The aforementioned Page class is only the base class. The actual class being used by the IIS worker process is a dynamically created derived class. So the ASP.NET HTTP runtime environment first determines the name of the class that will be used to serve the request. A particular naming convention links the URL of the page to the name of the class. If the requested page is, say, default.aspx, the associated class turns out to be ASP.default_aspx. The transformation rule applies a fixed ASP namespace and replaces any dot (.) with an underscore (_). If the URL contains a directory name, any slashes are also replaced with an underscore.

If no class exists with the specified name in any of the assemblies currently loaded in the AppDomain, the HTTP runtime orders that the class be created and compiled on the fly. This step is often referred to as the dynamic compilation of ASP.NET pages.

The source code for the new class is created by parsing the source code of the .aspx resource, and it’s temporarily saved in the ASP.NET temporary folder. The parser attempts to create a class with an initializer method able to create instances of any referenced server controls found in the ASPX markup. A referenced server control results from tags explicitly decorated with the runat=server attribute and from contiguous literals, including blanks and carriage returns. For example, consider the following short piece of markup:

When parsed, it sparks three distinct server control instances: two literal controls and a Button control. The first literal comprehends the text “” plus any blanks and carriage returns the editor has put in. The second literal includes “”.

Next, the Page-derived class is compiled and loaded in memory to serve the request. When a new request for the same page arrives, the class is ready and no compile step will ever take place. (The class

Return Main Page Previous Page Next Page

®Online Book Reader