Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A brief introduction to the ASP.NET Page object Model

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "introduction to the object model of ASP.NET page". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "introduction to the ASP.NET page object model"!

A brief introduction to the ASP.NET Page object Model

Each request for a Microsoft ASP.NET page received by Microsoft Internet Information Services (IIS) is handed over to the ASP.NET HTTP pipeline. The HTTP pipeline consists of a series of managed objects that process the request sequentially and complete the conversion from URL to plain HTML text. The entry point for the HTTP pipeline is the HttpRuntime class. The ASP.NET infrastructure creates an instance of this class for each AppDomain hosted in the worker process (note that the worker process maintains a different AppDomain for each ASP.NET application that is currently running).

The HttpRuntime class selects a HttpApplication object from the internal pool and lets it process the request. The main task of the HTTP application manager is to find the class that will actually process the request. If you request an .aspx resource, the handler is a page handler-an instance of a class that inherits from Page. The association between the resource type and the handler type is stored in the configuration file of the application. To be more precise, in the machine.config file

< httpHandlers>

A default set of mapping relationships is defined in the. However, applications can also customize their own list of HTTP handlers in a local web.config file. The following program line illustrates the code that defines the HTTP handler for the .aspx resource.

< add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory"/>

The extension can be associated with a handler class or, more generally, a handler factory (handler factory) class. In all cases, the HttpApplication object responsible for processing the request gets an object that implements the IHttpHandler interface. If the associated resource / class is parsed according to the HTTP handler, the returned class will implement the interface directly. If the resource is bound to the handler factory, another step is required. The handler factory class implements the IHttpHandlerFactory interface, and the interface's GetHandler method returns an IHttpHandler-based object.

How can the HTTP runtime complete the loop and process page requests? The IHttpHandler interface specifically provides the ProcessRequest method. By calling this method on the object that represents the requested page, the ASP.NET infrastructure initiates the process to generate output for the browser.

ASP.NET page object model: Page class

The type of HTTP handler for a particular page depends on URL. When URL is called, a new class is built and dynamically compiled into an assembly. The output of the parsing process used to check the .aspx source is the source code of the class. This class is defined as part of the ASP namespace and is given a name similar to the original URL. For example, if the URL endpoint is page.aspx, the class name is ASP.Page_aspx. However, you can also control the name of the class by programmatically setting the ClassName property of the @ Page instruction.

The base class of the HTTP processor is Page. This class defines the minimum set of methods and properties shared by all page handlers. Implement the IHttpHandler interface in the Page class.

In some cases, the base class of the actual handler is not Page, but a different class. For example, this can happen if code-behind is used. Code-behind is a development method that encapsulates the code required by a page into a separate C # or Microsoft Visual Basic.NET class. The code for a page is a set of event handlers and helper methods that actually create the behavior of the page. Can take advantage of

< script runat=server>

The tag defines this code as inline code, or you can put it in an external class-code-behind class. A code-behind class is a class that inherits from Page, but it has some additional methods that make it special. If specified, the code-behind class is used as the base class for the HTTP handler.

There is also a situation when the application configuration file

< pages>

When the PageBaseType property is redefined in the section, the HTTP processor is also not Page-based.

< pages PageBaseType="Classes.MyPage, mypage" />

The PageBaseType attribute indicates the type and assembly of the base class that contains the page handler. This class, derived from Page, automatically assigns a set of custom and extended methods and properties to the handler.

At this point, I believe that you have a deeper understanding of the "introduction to the object model of ASP.NET pages". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report