ASP. NET page exposure (1)

Source: Internet
Author: User

As a matter of fact, I have been not familiar with this aspect. It belongs to the kind of half-Bucket Water. I have read "Asp.net 2.0 technical insider" and I have a new understanding of this knowledge.

All resources accessible on IIS-based Web servers are grouped by file extension. Then, any input request is allocated to a specific runtime module for processing. ISAPI (Internet Server Application Programming Interface) extends the module for processing web resources in the context of IIS. It is a common legacy Win32 dynamic link library (DLL) that provides a large number of API functions with predefined names and prototypes, it provides developers with more powerful extensions of IIS functions. IIS and ISAPI extensions use these DLL items as a private communication protocol. When a request for a resource arrives, IIS first verifies the resource type. Static resources such as images, text files, HTML pages, and ASP pages without scripts are directly parsed by IIS. Resources that require processing on the server side are transferred to the registered module. For example, the. aspx file is assigned to an ISAPI extension process named c: \ windows \ Microsoft. NET \ framework \ v2.0.50727 \ aspnet_isapi.dll.

Resource ing is stored in the IIS metalibrary. ASP. NET makes modifications to the IIS metadatabase during installation to ensure that aspnet_isappi.dll can process some typical ASP. NET Resources. (. Asax,. ascx, ashx, asmx, aspx, axd, etc)

 

Iis5.0 Process Model

 

 

According to this model, when an HTTP resource request comes, aspnet_isapi.dll cannot process the. aspx file, but acts as a SchedulingProgram. It collects all information about the activation URL and basic resources, and sends the request to the Asp.net working process named aspnet_wp.exe of another process. The channel between the ISAPI extension and the worker process is implemented through the naming pipeline. A copy of the worker process is always running and all active web applications are hosted. Each web application is identified by its own virtual directory and belongs to a different application region (usually called appdomain ). Every time a customer processes a virtual directory for the first time.. net job process to create a new appdomain. after creating a new appdomain, Asp. net Runtime Library loads all the required assembly, and passes control to the managed HTTP pipeline for actual service requests. If a customer requests a page from a running web application, the ASP. NET Runtime Library only forwards the request to the existing appdomain associated with the virtual directory. If the appdomain does not load the Assembly that processes the page, it is created dynamically. Otherwise, it is used only when it is created for the first call.

 

Request page

Each request for accessing a referenced. aspx resource is mapped to a derived page class, which provides services. The ASP. net http runtime environment first determines the name of the class used to serve the request. There is a special naming convention that associates the URL of this page with the name of this class. For example, the default. aspx class ASP. default_aspx. If no class with this name exists in any Assembly currently loaded by appdomian, the HTTP Runtime Library creates the class and compiles it. TheSource codeBy parsing the source of the. aspx ResourceCodeThe created file is temporarily saved in the ASP. NET folder. Then compile the class and load the memory for service requests.

 

Process requests

As mentioned above, a class for parsing. aspx resources is created, then the HTTP runtime environment will activate the class through an interface (ihttphandler. The root page class implements this interface (two members: processrequest method and Boolean feature ). once the HTTP Runtime library obtains an instance of the class indicating the requested resource, activating the processrequest method will generate a process and the final response time of the browser will end. The steps and events for executing and triggering a processrequest call are collectively referred to as the page lifecycle.

 

What is the ASP. net http runtime environment?

ASP. net http runtime environment, which consists of four objects

(1) The httpruntime object webpage request processes the original HTTP load through an object pipeline, and generates some markup code for the browser at the end of the chain. The pipe entry point is the httpruntime class. Asp.net(( iis5.0is aspnet_wp.exe) The process activates this HTTP pipeline by creating an httpruntime object instance and then calling its processrequest method. Note: The httpruntime. processrequest method has nothing to do with the ihttphandler interface.

The httpruntime object initializes many internal objects that help the webpage request first when it is created. When the processrequest method is called, The httpruntime object first provides the webpage to the browser. It creates a new context for the request (an instance of the httpcontext class, encapsulates all http-specific information about the request), and initializes a special writer object, which will collect markup code. The httpruntime object uses the context information to locate or create a web application object that can process the request. Search for the application by using the virtual directory information contained in the URL. Httpapplicationfactor is used to search for or create a web application object. It is an internally used object that returns a valid object that can process the request .)

(2) Application Factory

During the lifecycle of an application, the httpapplicationfactory object maintains an httpapplication Object pool to serve incoming HTTP requests. After being activated, the application factory verifies whether the virtual folder targeted by the request has an appdomain. if the application is already running, the factory obtains an httpapplication from the available Object pool and passes it to the request. If the existing object is unavailable, a new httpapplication object is created.

(3) httpapplication object

The httpapplication object is a base class that represents a running ASP. NET application. A running ASP. NET application is represented by a dynamically created class inherited from httpapplication. By parsing the contents of the Global. asax file, you can create the source code of the dynamically generated application class.

An instance of the httpapplication derived class is responsible for managing the entire lifecycle of requests allocated to it. It can be reused only after it is completed. Httpapplication maintains an HTTP module object list, which can filter or modify the requested content. When a request passes a pipeline, the registered modules are called.

The httpapplication object determines the object type of the requested resource. This type is usually an ASP.. NET page, a Web service or a user control. then, httpapplication uses the appropriate processing factory to obtain an object that represents the requested resource. A handler factory object is an instance that implements the ihttphandlerfacory interface class and is responsible for returning an instance of a managed class that can process the HTTP request-an HTTP handler. The ASP. NET page is a handler object and an instance of classes that implement the ihttphandler interface.

(4) page Factory

The httpapplication Class determines the type of the object that must process the request and delegates a specific handler factory of this type to create an instance of this type. When the requested resource is a webpage, the factory is the pagehandlerfactory class. Httpapplication uses the information in the

 

Summary: The ASP. net workflow serves an input HTTP request. The request is first allocated to the aspnet_isapi.dll ISAPI extension, which passes it to the HTTP runtime pipeline. The ASP. NET pipeline entry point is the httpruntime class. Create a new instance of the class for each request, control its overall execution, and generate the browser response text. During instantiation, The httpruntime class executes the instantiation task. The first task is to create a wrapper object to encapsulate all http-specific information about the request. Then, the newly created object (an instance of the httpcontext object) is passed to the pipeline, and each module accesses the internal work object.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.