Asp.net large file upload (2)

Source: Internet
Author: User

Asp.net large file upload (2)

Wu jian2009-04-20

Reprinted please indicate the source: http://www.cnblogs.com/wu-jian/

3. Asp.net MPs queue

3.1 MAIN PROCESS

From the request to the ASP. NET worker process until it reaches the final processingProgramA series of steps and procedures have to be taken before. This step and process are called ASP in this document. net pipeline, about ASP. net pipeline I did not find the relevant official standard documentation, but according to Fritz Onion's "ASP. net basic tutorial.

1. The first step of the ASP. NET pipeline is to create an httpworkerrequest object that contains all information related to the current request, including the request URL and title.

2. Pass the request to the static processrequest method of the httpruntime class.
3. The first thing the httprutime class executes is to create an httpcontext object and initialize it with the httpworkerrequest class. The httpcontext class is the "adhesive" of the pipeline because it stores all information related to the current request in one place and combines all classes into one. When you create an httpcontext object for the first time, it allocates new instances of the httprequest and httpresponse classes and stores them in fields. It also provides dedicated accessors for applications and session states. (For more information about httpcontext, see section 3.2)
4. Once an httpcontext class is created, the httpruntime class requests an instance of the httpapplication derived class for the application by calling the static getapplicationinstance method of the httpapplicationfactory class.
5. getapplicationinstance either creates a new instance of the httpapplication (or derived class) class or pulls an instance from the Application Object pool. (For more information about httpapplication, see section 3.3)

6. Once an httpapplication class is created or retrieved, It is initialized and allocated to all modules defined for this application during initialization. A module is a class that implements the ihttpmodule interface and provides services for requests before and after a process.
7. Once a module is created, the httpruntime class calls its beginprocessrequest method and requires the newly retrieved httpapplication class to provide services for the current request. Then, find the appropriate processing factory for the current request.
8. Create a handler and pass the current httpcontext. Once the processrequest method returns, the request is complete.

 

3.2. httpcontext

Httpcontextasp.net is the most important class in the Asp.net pipeline. It maintains all request-related data and can be accessed by most elements in the pipeline. During the request lifecycle, the context is always valid. You can also use static httpcontext. current attribute access, as its name implies, httpcontext object represents the context of the current active request, because it contains references to all the required objects you will use in the request lifecycle, for example, request, response, application, server, and cache. You can use httpcontext. Current to access these objects at any time during request processing. Remember that httpcontext is a friend of yours. You can use httpcontext to obtain relevant data at different stages of request or page processing.

 

3.3. httpapplication

Httpapplication is mainly used as the event controller of the Asp.net pipeline. It is responsible for request transmission and notifies the application of what is happening by triggering an event. Httpapplication itself does not know the data sent to the web program. It is only a message sender and only responsible for communications between events. It triggers the event and sends the information to the called method by passing the httpcontext object. Events in the Asp.net pipeline are triggered one by one in sequence, as shown in:

Events provided by httpapplication to the outside world

Event Activation reason Sequence
Beginrequest New request received 1
Authenticaterequest Security identity of the user has been established 2
Authorizerequest User Authorization verified 3
Resolverequestcache After authorization, if the cache entry is found before the handler is called, the cache module is used to bypass the execution of the handler. 4
Acquirerequeststate Load session Status 5
Prerequesthandlerexecute Before the request is sent to the processing program 6
Postrequesthandlerexecute After the request is sent to the processing program 7
Releaserequeststate After all request processing programs are completed, the status module is used to save status data. 8
Updaterequestcache After the processing program is executed, the cache module is used to store the response in the cache. 9
Endrequest After the request is processed 10
Disposed Just before closing the application  
Error When an unhandled application error occurs  
Presendrequestcontent Before the content is sent to the customer  
Presendrequestheaders Before the HTTP title is sent to the customer  

 

3.4. ihttpmodule

Modules (httpmodule) are the most powerful extensions. They are created when an application is created for the first time and exist throughout the life cycle of the application. They can be connected to any httpapplication event. It is usually used to pre-process and post-process requests, and is similar to the ISAPI filter in IIS in many aspects. ASP. NET itself uses modules to implement many application-level functions, including authentication, authorization, caching, and off-process session Status management.
The following example shows the implementation of an httpmodule:

 

C #

Using System;
Using System. Web;

Namespace Test
{
Public Class Mymodule: ihttpmodule
{
Public Void Dispose (){}
Public Void Init (httpapplication APP)
{
App. beginrequest + = New Eventhandler ( This . Application_beginrequest );
App. endrequest + = New Eventhandler ( This . Application_endrequest );
}
Protected Void Application_beginrequest ( Object Sender, eventargs E)
{
Httpapplication app = Sender As Httpapplication;
App. Context. response. Write ( " This is mymodule application_beginrequest. " );
}
Protected Void Application_endrequest ( Object Sender, eventargs E)
{
Httpapplication app = Sender As Httpapplication;
App. Context. response. Write ( " This is mymodule application_endrequest. " );
}
}
}

Web. config

< Httpmodules >
< Add Name = "Mymodule" Type = "Test. mymodule, test" />
</ Httpmodules >

 

3.5. ihttphandler

C #

Using System;
Using System. Web;

Namespace Test
{
Public Class Myhandler: ihttphandler
{
Public Void Processrequest (httpcontext cont)
{
Cont. response. Write ( " This is myhandler. " + " <Br/> " );
}
Public Bool Isreusable {
Get { Return True ;}
}
}
}

Web. config

< Httphandlers >
< Add Verb = "Get" Path = "*. Aspx" Type = "Test. myhandler, test" />
</ Httphandlers >

 

From aboveCodeIt can be found that implementing an httphandler seems very simple. It only contains a processrequest () method and an isreusable attribute. But is it so simple? Remember, both webforms and WebServices are implemented as httphandler. In this seemingly simple interface, many implementation processes are actually hidden. We just made a simple output. However, the key point is that processrequest () can be used to obtain an instance of an httpcontext object and understand that this separate method can process a Web request from the beginning to the end.
In addition, you may notice that the ihttphandler interface supports a read-only attribute named isreusable, which indicates whether an instance with a specific handler can be securely shared. If you build a Custom Handler and return true from this attribute, Asp.net shares the handler instance when the handler instance is used to provide services to the request. If false is returned, a new instance of the processing program is created for each service request. Generally, there is no big difference in whether the processing program is shared or not, because the instantiation mechanism in CLR is very effective with the garbage collector, so sharing the processing program class will not benefit much. One case of sharing is that it takes a lot of time for a processing program, such as retrieving data from a database. The standard handlers provided by Asp.net are never shared by the handler.

 

Previous Article: Asp.net large file upload (1) | next article: to be continued

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.