A request from the HTML code URL string to the "long tortuous" road

  Author: Dino Esposito Source: msdn ASP.NET HTTP running a request from the URL string HTML code to the "long tortuous" road 
  Dino Esposito 
Wintellect
  July 10, 2003 Abstract: This paper describes the HTTP runtime component, as well as in dealing with the ASP.NET application of the logic used in the request.    The article also to Web Garden model and the latest IIS 6 to start the process model, the process of supporting acts, and that the HTTP request into pure HTML text as a whole.    (This article contains some point to the English site for the link.) 

  Apply to: 
  Microsoft ® ASP.NET 

  Contents Introduction 
  ASP.NET structural components 
  Web Garden Model 
  HTTP pipeline temporary files and page brief summary procedures set no matter what the underlying platform use, reliability and performance are all on the main Web application requirements, although, in a sense, these two requirements are contradictory.    For example, to build more reliable, more robust applications, may need to be Web servers and application specific separation, the application of the process to work.    However, if different from the Web server in the process of memory work environment, the application will be slow.    Therefore, the need to take reasonable measures to ensure that the process of code running as soon as possible. 

  Construction of the Microsoft ® ASP.NET runtime environment, based on the design principles: give full consideration to reliability and performance.    The ASP.NET process model contains elements of the two systems - a Web server exists in the process of the process of connector, an external auxiliary process.    In addition, the structure of ASP.NET runtime highly scalable capacity, the automatic use of multi-processor hardware arbitrarily selected processors.    This mode is called the "Web Garden", which can support multiple processes running at the same time, and all are in the process of independent processors. 

  Highly summarized, ASP.NET runtime has three attributes: 

  ASP.NET applications and support complete separation between process.    Supplementary services provided the process of life will not affect the application's life.    In other words, the applications are up and running, supporting process can be terminated at any time. 
  Although never in ASP.NET applications within a Web server running in the process, but in most cases, their overall performance is still close to the process within the application performance. 
  Architecture for Web Garden provides a built-in configuration and support.    Simply check the settings in configuration files, the process can be assisted cloning themselves, and to take advantage of all the process is closely related to the CPU.    Therefore, in most cases, you will have multi-processor computer can be obtained scalability will become linear growth trends.    (This article will describe in more detail behind this.) 
  This article introduces the ASP.NET runtime environment composed of elements, and then step-by-step on the request from the URL into pure HTML text of the "long and tortuous" process. 

  Unless stated otherwise, are presented below in that the default ASP.NET process model, which Microsoft ® Internet Information Services (IIS) 5.x the only model. 

  ASP.NET implementation of structural components of ASP.NET application needs the support of the host Web server.    In the Microsoft ® Windows ® Server platform, the Web server from inetinfo.exe called the executable file that IIS.    Windows 2000 and above versions of the operating system itself have been providing a Web server.    But needs attention, in the Microsoft ® Windows Server ™ 2003, no default installation IIS and ASP.NET, it is necessary to click the "control panel" in the "Add or Remove Programs" small procedure will be added to the system. 

  IIS is a trustee of the executable program, it offers a module based on the expansion and ISAPI filter module can be extended model.    Through the preparation of these modules, developers can directly manage resources on specific types of requests, and in all pre-defined steps to receive the request.    Expansion and filter some DLL, can be exported some of the names and signatures of known function.    These plug-in component in IIS configuration is registered in the database and configuration. 

  Only a few clients request by the types of resources directly addressed by the IIS.    For example, the HTML pages, text files, JPEG and GIF image processing imported request by the IIS.    On the Active Server Page (*. asp) document entitled asp.dll request by calling for expansion of the ASP Analysis module.    Similarly, ASP.NET resources (for example, *. aspx, *. asmx, *. ashx) at the request will be transmitted to the ASP.NET ISAPI extension.    The system is a component of the Win32 DLL called aspnet_isapi.dll.    ASP.NET expansion can be dealt with a variety of resource types, including Web services and HTTP call handling procedures. 

  ASP.NET ISAPI extension is a Win32 DLL, not integrated managed code.    It is to receive and distribute the resources of the various requests for ASP.NET control center.    According to its design, the module IIS exist in the process of having administrator privileges to run the SYSTEM account.    Developers and system administrators can modify this account.    ASP.NET ISAPI extension of the process responsible for calling ASP.NET support (aspnet_wp.exe), and the process is responsible for controlling the execution of the request.    In addition to the request for outside support ASP.NET ISAPI also monitor the operation of the process and to a certain degree of performance degradation process will be cancelled. 

  Auxiliary process is a small amount of Win32 shell code, integrated common language runtime (CLR) and running managed code.    It is responsible for dealing with the ASPX, and ASHX ASMX resource requests.    Generally speaking, this process on one computer to be only one instance.    ASP.NET activation of all current applications which are running in each application are located in a separate AppDomain.    However, as mentioned above, the process of auxiliary support Web Garden model which is the process of running the same copy with the process closely related to the CPU.    (For more information, please refer to the back of this paper, "Web Garden model".) 

  ISAPI and supporting the process of communication between a group using the named pipe.    A named pipe is a Win32 mechanisms for the process of cross-border transmission of data.    As the name suggests, the work of naming pipeline and the pipeline similar way: at one end input data, output in the other end of the same data.    The establishment of the pipeline can connect local process, can also connect remote computers running on the process.    As for the local inter-process communications, in the pipeline is Windows the most effective and flexible tool. 

  To ensure that access to optimal performance, aspnet_isapi named pipe using asynchronous request will be transmitted to the process and agreed to support response.    On the other hand, in the process of supporting the need for IIS environment information (ie server variables) when using synchronous pipeline.    Aspnet_isapi modules to create a fixed number of named pipe, and the use of overlapping operations through small thread pool the same time deal with the connection.    When the pipeline through data exchange operation after the completion of routine will be disconnected client, and re-use of the pipeline for new examples of client services.    Thread Pool and overlapping operations can ensure that the ASP.NET ISAPI performance at a satisfactory level.    However, the extension will not deal with aspnet_isapi HTTP request. 

  ASP.NET request processing logic can be summarized as the following steps. 

  When the request arrived, IIS checks resource types and call ASP.NET ISAPI extension.    If the process of opening the default model aspnet_isapi will request queue, and will be allocated to support the request process.    At the request of all data through asynchronous I / O sent.    If IIS 6 opening of the process model, the request will automatically be assisted in the process (w3wp.exe) in the queue, the auxiliary application process for handling their IIS application pool.    IIS 6 does not understand the process of supporting and hosting ASP.NET code any case, it deals only with *. aspx extension and loading aspnet_isapi module.    When ASP.NET ISAPI 6 in the IIS process model runs, it's different working methods, w3wp.exe only in the context of supporting the process of loading CLR. 
  Receipt of the request, ASP.NET support ASP.NET ISAPI process will be notified, it will request service.    Notice through synchronous I / O to achieve.    The reason why the use of synchronous model, because only in the ISAPI request internal request form is marked "executing", auxiliary process can begin to deal with it.    If the request has been supported by a special treatment process, then it can not be assigned to other processes, unless the original process has been cancelled. 
  In the context of supporting the process of execution of the request.    Sometimes, the process may need support to complete the pullback ISAPI request, but also said that enumeration is the need for server variables.    Under such circumstances, the process of supporting synchronous pipeline will be used, because it can maintain the order of request processing logic. 
  Upon completion, the response was sent to open the aspnet_isapi asynchronous channels.    Now, the status of the request into a "Done", after requests from the table is deleted.    If supporting the process of collapse, all requests are being processed will remain "executing" status and continue for some time.    If aspnet_isapi detected auxiliary process has been cancelled, it will automatically terminate request and the release of all relevant IIS resources. 
  Described above refers to the default ASP.NET process model that is running IIS 5.x a working model.    IIS 6 (Windows Server 2003 provides) on the working methods of default ASP.NET process model have influenced it.    When integrated with IIS 6.0, ASP.NET 1.1 will automatically adjust their own work methods to adapt to the host environment.    At this time, no longer need to use auxiliary aspnet_wp process defined in the machine.config file certain configuration parameters has been overlooked.    From the point of view of ASP.NET, IIS 6 is the greatest change in the request aspnet_isapi everything under the control of, and are in the process of w3wp.exe assisted in the context.    Auxiliary process accounts for their Web applications installed application pool account.    By default, the account is NETWORKSERVICE-, it is a built-in weak accounts, in the functional equivalence with the ASPNET. 

  Assisted by a process called recovery process (Recycling) functional control.    Aspnet_isapi functional recovery of the process, when the existing process of memory consumption too much, too slow or hangs response can be automatically activated when the new process.    As this happens, it will be a new example of the new request, the new examples of the activities to a new process.    However, assigned to the old process all requests still hung state.    If the old end of the process and at the request of a hung enter idle state, the process is terminated.    If supporting the process of collapse, or because of other reasons to stop handling of the request, all will be hung at the request of re-assigned to the new process. 

  Although ASP.NET ISAPI and supporting ASP.NET runtime process is a key component of the structure, but there are other executable file also play a role.    The following table shows a list of all of these components. 

  Table 1: ASP.NET runtime environment constitute the executable file 

  Name Type account 
  Aspnet_isapi.dll Win32 DLL (ISAPI extensions) LOCAL SYSTEM 
  Aspnet_wp.exe Win32 EXE ASPNET 
  Aspnet_filter.dll Win32 DLL (ISAPI filter) LOCAL SYSTEM 
  Aspnet_state.exe Win32 NT Service ASPNET 

  Aspnet_filter.dll component is a small Win32 ISAPI filter, used to backup ASP.NET application without Cookie session state.    In Windows Server 2003, when the process of opening IIS 6 model, will be screened aspnet_filter.dll Bin directory of resources for the non-enforceable. 

  Aspnet_state.exe the role of Web applications is more important, because it used to manage session state.    The service is optional, and can be used in Web applications from memory space preservation session state data.    The executable file is a NT service, both in the local operation, remote operation.    When the service is activated, ASP.NET applications can be configured to all session information will be stored in the memory in the process.    A similar programme is to provide more reliable data storage, from the process of recovery and ASP.NET application failures.    The services in the local ASPNET account running, but it can be used for the control and management of services (Service Control Manager) interface to configure it. 

  Another should be introduced by the executable file is aspnet_regiis.exe, although strictly speaking, it does not belong to ASP.NET runtime structure.    The Utility can be used to configure the environment, to a computer in the parallel implementation of different versions of ASP.NET, IIS can also be used to repair damage and ASP.NET configuration.    The practical procedures of the ways is to update the database stored in the configuration of IIS root directory and subdirectories in the script mappings.    Script type and mapping resources ASP.NET module of a link between relations.    Finally, the tool may also be used to display has been installed ASP.NET version of the state, the implementation of other configuration operations, such as the granting of a specific folder of the NTFS permissions, create customer script directory. 

  Web Garden Model 
  Web Garden machine.config model can be adopted in the document <processModel> part to configure.    Please note that <processModel> is the only part not on the application-specific documents in the web.config part of the configuration.    That is to say, Web Garden model can be applied to a computer running all applications.    But through the use of source files in the machine.config <location> nodes, can adjust for various applications of computer settings. 

  <processModel> Some of the two properties can affect Web Garden model, and they are webGarden cpuMask.    WebGarden attribute accept Boolean value that the use of a number of auxiliary process (a related correspondence of a process CPU).    By default, the value of the property to false.    CpuMask attribute preserve a DWORD value, the value of the binary that can run ASP.NET support for the process of providing a bit CPU shielding.    The default value of -1 (0xFFFFFF), said it would use all available CPU.    If webGarden attribute to false, then the contents of cpuMask attributes will be ignored.    CpuMask attribute also is running for the aspnet_wp.exe set up a few copies of the ceiling. 

  As the saying goes, "the flash is not gold," using very appropriate here.    Web Garden model makes several auxiliary processes can run simultaneously.    However, it should be noted that all the process will have its own state of the application, within the process session state, ASP.NET cache, as well as static data and the applications for other content.    Web Garden opening mode, the CPU will be ASP.NET ISAPI as much as possible the number of start-assisted process, the process of supporting each of the next process is the integrity of cloning (with each process are closely related to the corresponding CPU).    In order to balance the work load, at the request of the introduction of the Single Cycle approach to the process of running between the division.    Assisted in the process, as in the same single processor is recovered.    Please note that the operating system ASP.NET inherit all of the restrictions on the use of CPU, and does not include the realization of the definition of semantic constraints. 

  In short, Web Garden model does not apply to all applications.    The status of the application, the performance of its losses more.    Work in the shared memory data storage block, in order to enter a process of change can be immediately know other processes.    However, the handling of the request, the data is copied to work in the context of the process.    Therefore, various supplementary process will be dealt with the work of their own data, and the status of the application, the greater the loss of performance.    In view of this, careful and wise application benchmark testing is absolutely necessary. 

  Only after the restart IIS, the configuration file <processModel> part of the changes will come into force.    In IIS 6, the Web Garden mode IIS configuration parameters stored in the database, and cpuMask webGarden attributes are ignored. 

  HTTP pipeline 
  ASP.NET ISAPI extension activated auxiliary process, it will transfer part of the command line parameters.    Auxiliary process to implement the use of these parameters before loading CLR needs of the task.    The value of transmission include: COM and DCOM security of the authentication requirements of the grade, you can use the number of the named pipe IIS process and logo.    Is the name of the named pipe using IIS process of the pipeline and allow the identification of randomly generated.    Auxiliary process is not available to receive the channel name, but the name can receive recognition for the information pipeline. 

  COM and DCOM security, and Microsoft ®. NET Framework what?    In fact, the CLR as a COM object is provided.    To be more precise, by the COM CLR itself is not a code, but at the CLR interface is a COM object.    Therefore, the process of loading CLR support means, and loading in the same manner as COM object. 

  When ASPX requests encountered IIS, the Web server will be chosen authentication model (anonymous, Windows, Basic or Digest) to allocate a token.    When the process received support to deal with the request, the token is passed to support the process.    Auxiliary request by the threads in the process of acquisition.    The thread imported from the initial request access to the IIS thread succession identity tokens.    In the aspnet_wp.exe, responsible for the handling of the request depends on the actual account in the special ASP.NET applications is how to configure the simulation.    If the simulation is disabled (the default), the thread will be assisted in the process of running accounts.    By default, the account in the ASP.NET process model for the ASPNET, in the IIS process model for the 6 NETWORKSERVICE.    These two accounts are "weak" accounts provided by the relatively limited functions can be effectively able to resume sexual assault (Revert-to-self Attack).    (Replies sexual assault refers to the simulation of the security of the client return to the parent process Token Token. Support for the process of distribution of weak accounts can defeat such attacks.) 

  Highly summarized, ASP.NET support the completion of the process is one of the main tasks will be to request a series known as the custodian of the HTTP pipeline object.    To enable HTTP pipeline, you can create a new category of HttpRuntime example, and then call its ProcessRequest method.    As mentioned above, only in ASP.NET always runs a support process (unless enabled Web Garden model), the process by the independent AppDomain in the management of all Web applications.    Each has its own AppDomain HttpRuntime By that point the input channels.    HttpRuntime object initialization request contribute to the achievement of a series of internal targets.    Helper including cache management (Cache object) and internal documentation system monitors (for the application of a source file changes).    HttpRuntime request for the creation of context and used with HTTP request relevant information packed context.    HttpContext context of the examples used to that. 

  Another HTTP runtime settings initially created Helper Object is text writing, for the response contains the browser text.    HttpWriter text is written with such examples, the object code of the page to send a copy of Programming cache.    HTTP runtime is initialized, it will find applications to achieve the targets of the request.    HttpApplication object is the application of the examples of such documents is behind the global.asax category.    Global.asax in programming is optional, but in the construction of the structure is necessary.    Therefore, if the application did not build category, we must use the default target.    ASP.NET running factories, including several intermediate category can be used to locate and return the Handler object to the effective handling of the request.    The whole process used in the first category is HttpApplicationFactory factories.    Its main task is to use the URL information to find URL directory and virtual pool of HttpApplication object relations between the match. 

  Application of the factory acts can be summarized as follows: 

  Factory Maintenance HttpApplication object pool, and use them to deal with the application's request.    Pool life and the life of the same application. 
  Application procedures for the arrival of a request, the plant extract the relevant application types of information (global.asax), set up to monitor changes to files, create applications Application_OnStart state and trigger events. 
  Factories category of access to a pool HttpApplication example, and to deal with the request Add example.    If the targets are not available, the creation of a new HttpApplication object.    To create HttpApplication object, the need to complete the application procedures global.asax file compiler. 
  HttpApplication begin to deal with the request, and only after the completion of this request can be dealt with the new request.    If you receive the same resources from the new request, the other objects from the pool to deal with. 
  Application object allows all registered HTTP module to request a pretreatment, and identify the most suitable for handling of the request processing types.    View this through the expansion of the URL request and the information in the configuration file to complete. 
  HTTP process is achieving some of the IHttpHandler interface.    . NET Framework is a common type of resources provided some pre-defined procedures, including ASPX pages and Web services.    Machine.config in document <httpHandlers> part of the definition of HttpApplication object must be examples of specific types of resources to deal with the request of the class names.    If Helper category is a processing factory, GetHandler methods will be used to determine the types of procedures.    At this time, from a group of similar objects in the types of access to appropriate procedures, and its allocation to deal with the request. 

  IHttpHandler interface provides two methods: IsReusable and ProcessRequest.    The former will return a Boolean value that the process can be pooled.    (Most pre-defined procedures are compiled, but you can define the needs of each new example of the process.) ProcessRequest method of dealing with specific types of resources includes all the necessary logic.    For example, ASPX pages procedures based on the following pseudo-code: 

  Private void ProcessRequest () 
  ( 
  / / To determine whether the request is made (postback) 
  IsPostBack = DeterminePostBackMode (); 

  / / Trigger ASPX source code Page_Init incident 
  PageInit (); 

  / / Load the ViewState to deal with have been sent value. 
  If (IsPostBack) ( 
  LoadPageViewState (); 
  ProcessPostData (); 
  ) 

  / / Trigger ASPX source code Page_Load event 
  PageLoad (); 

  / / 1) have been sent to deal with the value of (when 
  / / Create dynamic controls) 
  / / 2) to attribute changes to the server-side events upgrade to the input drive 
  / / Control (ie change the status of the box) 
  / / 3) to the implementation of all the events related code 
  If (IsPostBack) ( 
  ProcessPostDataSecondTry (); 
  RaiseChangedEvents (); 
  RaisePostBackEvent (); 
  ) 

  / / Trigger ASPX source code Page_PreRender incident 
  PreRender (); 

  / / Control to preserve the current status in the ViewState 
  SavePageViewState (); 

  / / Contents will be presented to HTML pages 
  RenderControl (CreateHtmlTextWriter (Response.Output)); 
  ) 

  No matter what type of call resources, based on HTTP processing model is the same.    Only with the types of resources and changes in the elements of change is handling procedures.    View HttpApplication object responsible for what procedures should be used to deal with the request.    HttpApplication object is also responsible for testing the dynamic created by the procedures set that resources (such as. Aspx pages or. Asmx Web services) by the changes.    If detected changes, the application will ensure that the compiler targets and loading the requested resources to the latest sources. 

  Provisional pages of documents and procedures set to a comprehensive understanding of ASP.NET HTTP operation, let us take a look at the request ASP.NET pages, the file system of the changes.    Next, you will learn from the HTTP pipeline management and monitoring targets for a group of dynamic creation of temporary files. 

  While pages can be the core of the code in isolation behind the C # code, or Microsoft ® Visual Basic ®. NET category, but Web pages can be prepared and deployed for. Aspx text file.    In order to show the URL of the page,. Aspx file in the application of Web space must always be available.    . Aspx document will determine the actual contents of the object is loaded application procedures set (or a number of procedures set). 

  According to its design, HttpApplication object will find a document on request, the name of the ASPX category.    If a page named sample.aspx would have loaded the corresponding class ASP.sample_aspx.    Application objects in Web applications all the procedures set folder finding such categories, including overall these folders procedures set cache (GAC), Bin subfolders and Temporary ASP.NET Files folder.    If you do not find this category, HTTP structure will be analyzed. Aspx document source code, the creation of a Visual Basic or C #. NET category (which create specific categories, depending on. Aspx page set up language), while its compiler .    Create a new set of procedures is the name of a randomly generated, in particular on the application of the subfolders in the path as follows: C: \ WINDOWS \ Microsoft.NET \ Framework \ v1.1.4322 \ Temporary ASP.NET Files. 

  Subfolders v1.1.4322 specific to ASP.NET 1.1.    If you are using the ASP.NET 1.0, the version subfolders, will be different, that subfolder called v1.0.3705.    Another visit to a page, procedures have been set there, no need to re-create.    However, HttpApplication object is to define the specific procedures set in the pages whether there?    It must scan a large number of documents each folder?    No, is not the case. 

  Application Object only Show Temporary ASP.NET Files folder in a special folder contents.    Specific criteria (specific to the application's path) from HttpRuntime.CodegenDir attribute return.    If it is his first visit. Aspx files (pages that have not yet established procedures set), the folder does not exist in the ASPX pages to the beginning of the XML file name.    For example, a dynamic set of procedures should be sample.aspx pages of entries are as follows: 

  Sample.aspx.XXXXX.xml 
  XXXXX placeholder is a hash code.    Read through the contents of the XML file, the application can understand object to the procedures set loading, as well as to the name of the category in which access.    The following code fragment is that the typical Helper document content.    ASP.sample_aspx category contains the name of the procedure is set mvxvx8xr. 

  <preserve Assem="mvxvx8xr" type="ASP.sample_aspx"> 
  <filedep Name="c:\inetpub\wwwroot\vdir\sample.aspx" /> 
  </ Preserve> 

  Of course, only in the analysis filedep document the source code to produce dynamic program set when creating the document.    Filedep done on the document will make any changes to procedures set invalid, the next request need to be recompiled.    It must be noted that, in future versions of ASP.NET framework, the implementation process may be more change.    No matter what the reason, if you decide to use the current application it must be very careful. 

  As for the updated pages and the creation of a new set of procedures, ASP.NET will verify whether the procedures can be deleted the old set.    If the old procedures set contains only the revised pages of categories, ASP.NET will try to delete and replace the procedure set, it will retain the old procedures set of procedures to create a new set. 

  In the removal process, the procedure may find ASP.NET Set document has been loaded and locked.    Under such circumstances, can the old procedures add a set. "DELETE" expansion, in order to be re-named.    (Note that all Windows files can be used in the process of re-named.) To restart as long as applications (for example, because of an application procedures and documents such as web.config global.asax a change), these temporary. DELETE document will be deleted.    However, in dealing with a request, ASP.NET runtime will not delete these files. 

  Please note that the default, the entire application process before the restart, each ASP.NET applications can be recompiled maximum of 15 pages, will also lose some conversation and application data.    When compiling the recent number of more than <httpRuntime> numRecompilesBeforeAppRestart attributes part of the set threshold, it will be unloaded AppDomain, and restart the application.    Attention should be paid to in the. NET Framework, you can not unload a single set procedures.    CLR AppDomain can be unloaded from the smallest block. 

  Summary 
  ASP.NET application has two characteristics: process model and object model pages.    ASP.NET early use of some of the features IIS 6.0, IIS 6.0 and Windows Server 2003 is provided in the new, innovative Microsoft Web information services.    It is particularly worth mentioning is that in the process of supporting the independent operation of ASP.NET applications, its behavior and IIS 6 application of all the same.    Moreover, while there will be run-time anomaly, memory leaks or procedural errors, ASP.NET runtime can automatically support the recovery process to ensure the realization of superior performance.    This function has become IIS 6.0 system functionality. 

  In this article, I gave an overview of the default ASP.NET process model of knowledge, and IIS-level code (ASP.NET ISAPI extensions) and the interaction between the support process.    At the same time, and IIS 6 on the process of the latest differences between the model.    In this paper, the page object model on less, and I will in the future further on the article.    Welcome to read! 

  To deeper understanding of ASP.NET, and HTTP runtime object model pages, please refer to Microsoft Press in 2003, I published a book Programming Microsoft ASP.NET. 

  About the author 
  Dino Esposito from Rome, Italy, is one of the training of teachers and advisers.    The members of the group as a Wintellect, Dino specializes in ASP.NET and ADO.NET, mainly in Europe and the United States engaged in teaching and consulting work.    Dino also managed ADO.NET Wintellect the courseware for MSDN Magazine's Cutting Edge column written articles.    Contact with him, please send an e-mail to dinoe@wintellect.com. 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: , , , ,

Releated Java Articles

Comments

Leave a Reply