ASP. NET Framework (3)

Source: Internet
Author: User
ASP. NET Framework (3) March 25, 2004
Author: uestc95
Articletype: original
E-mail: uestc95@263.net
. NET Framework Version: 1.0.3705 official version
Vs. Net (C #) version: 7.0.9466 official version

The appetite for the past few days is quite good. Although it is not "delicious", it is also good. I hope it will increase by a few pounds.
The two last questions we raised at Chapter Two are estimated to have come out early ,:)
First: Why can't session be used in httpmodule?
Second: Where are the default httpmodules configured?

Let's pick up the soft persimmon first. The answer to the second question is: configure it in the file machine. config, for example, in the C: WI in your system file directory

Nntmicrosoft. netframeworkv1.0.3705configmachine. config.
Although it is a soft persimmon, there are still some stuff in it, that is, what is the relationship between machine. config and our common web. config?

What about the system? When ASP. NET Framework starts to process an HTTP request, it loads machine. config and your request page in sequence.

The configuration in the web. config file in the directory contains the <remove> label. You can understand it without saying anything. If you are in machine. c

Onfig is configured with an httpmodule. You can still remove this ing from the latest web. config file.
As for the first question, haha, if you have carefully run the last file but have not thoroughly studied it yourself, you will surely feel

The session cannot be used in httpmodule ,:). If you find that the question you raised last time is a "problem", congratulations, you didn't fall into the box I intentionally gave and are very skeptical ,:)
Today, Let's explain the relationship between httpmodule and httphandler. When today's "Diary" is complete, you will find the answer to the first question.

Chapter Three -- go deep into httpmodule

We once mentioned that when an HTTP request is ASP. after the Net Framework is captured, it will be handed over to the httpmodule and httphandler for processing in sequence, but it cannot be understood that the httpmodule and httphandler are completely independent. In fact, when an HTTP request is passed in an HTTP module, the control is handed over to httphandler in an event. After the real processing is completed in httphandler, the control is handed back to httpmodule. That is to say, when a request passes through her, the httpmodule will communicate with httphandler at an appropriate time. How can it communicate? This is what we mentioned below.
We mentioned that the most initial event in httpmodule is beginrequest, and the final event is endrequest. If you carefully look at the source provided last time Program In the method Init (), we should find that the parameter we pass is an httpapplication type, and the two events we once mentioned are one of the events passed in httpapplication.
Httpapplication has other events as follows:
Application. beginrequest
Application. endrequest
Application. prerequesthandlerexecute
Application. postrequesthandlerexecute
Application. releaserequeststate
Application. acquirerequeststate
Application. authenticaterequest
Application. authorizerequest
Application. resolverequestcache
Application. presendrequestheaders
Application. presendrequestcontent

It should be noted that the application will continue to be executed after the event endrequest. presendrequestheaders and application. the presendrequestcontent event, and the two events should be clearly identified from the name. Yes. Once these two events are triggered, the entire HTTP request processing is completed. In these two events, the processed data streams are transmitted to the client. When you see this, you should have a question: Why didn't you see httphandler? Didn't I mention that httphandler actually processes HTTP requests? If you have this question, it means you are reading it carefully, and I am not tired of typing ,:).
As a matter of fact, I mentioned at the beginning that an HTTP request will pass the request to httphandler at a certain time point (specifically, it should be an event) during the HTTP module transfer process. This event is resolverequestcache. After this event, httpmodule will create an httphandler entry instance (ready, :)), but the control is not handed over at this time, instead, it will continue to trigger the acquirerequeststate and prerequesthandlerexecute events (if you do ). You see, the prefix of the last event is pre. This indicates that the next step is to go to httphandler. Indeed, as we guess, after the prerequesthandlerexecute event, httpmodule will temporarily hand over control to httphandler for real HTTP request processing. In httphandler, processrequest is executed to process the request. After httphandler completes processing, it will return the control to the httpmodule, And the httpmodule will continue to perform layer-by-layer forwarding actions on the processed HTTP request until it is returned to the client.
How about it? I have already drawn a lifecycle chart for the entire httpmodule on hand. I can only use characters to describe the process here, if you want this image, you can mail it to me and I will mail it to you.
The lifecycle diagram of HTTP request in the entire httpmodule:

HTTP request starts
|
Httpmodule
|
Httpmodule. beginrequest ()
|
Httpmodule. authenticaterequest ()
|
Httpmodule. authorizerequest ()
|
Httpmodule. resolverequestcache ()
|
Create httphandler Control Points
|
Next process (httphandler has been set up, and the session will be available later)
|
Httpmodule. acquirerequeststate ()
|
Httpmodule. prerequesthandlerexecute ()
|
Go to httphandler to process httprequest
|
Httphandler. processrequest ()
|
Return to httpmodule for processing (the httphandler lifecycle ends and the session becomes invalid)
|
Httpmodule. postrequesthandlerexecute ()
|
Httpmodule. releaserequeststate ()
|
Httpmodule. updaterequestcache ()
|
Httpmodule. endrequest ()
|
Httpmodule. presendrequestheaders ()
|
Httpmodule. presendrequestcontent ()
|
Return the processed data to the client
|
The entire HTTP request processing is complete.


In the above figure, we should find the answer to the first question we asked last time.
To verify the above process, we can use the following httpmoduel to verify it.
Note that the following is the class content, and the framework is the one we gave the previous time. You can add it yourself:

Public void Init (httpapplication Application)
{
Application. beginrequest + = (New eventhandler (this. application_beginrequest ));
Application. endrequest + = (New eventhandler (this. application_endrequest ));
Application. prerequesthandlerexecute + = (New eventhandler (this. application_prerequesthandlerexecute ));
Application. postrequesthandlerexecute + = (New eventhandler (this. application_postrequesthandlerexecute ));
Application. releaserequeststate + = (New eventhandler (this. application_releaserequeststate ));
Application. acquirerequeststate + = (New eventhandler (this. application_acquirerequeststate ));
Application. authenticaterequest + = (New eventhandler (this. application_authenticaterequest ));
Application. authorizerequest + = (New eventhandler (this. application_authorizerequest ));
Application. resolverequestcache + = (New eventhandler (this. application_resolverequestcache ));
Application. presendrequestheaders + = (New eventhandler (this. application_presendrequestheaders ));
Application. presendrequestcontent + = (New eventhandler (this. application_presendrequestcontent ));
}

Private void application_prerequesthandlerexecute (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_prerequesthandlerexecute <br> ");
}

Private void application_beginrequest (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_beginrequest <br> ");
}

Private void application_endrequest (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_endrequest <br> ");

}

Private void application_postrequesthandlerexecute (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_postrequesthandlerexecute <br> ");

}

Private void application_releaserequeststate (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_releaserequeststate <br> ");

}

Private void application_updaterequestcache (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_updaterequestcache <br> ");

}

Private void application_authenticaterequest (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_authenticaterequest <br> ");

}

Private void application_authorizerequest (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_authorizerequest <br> ");

}

Private void application_resolverequestcache (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_resolverequestcache <br> ");

}

Private void application_acquirerequeststate (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_acquirerequeststate <br> ");

}

Private void application_presendrequestheaders (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_presendrequestheaders <br> ");

}

Private void application_presendrequestcontent (Object source, eventargs E)
{
Httpapplication application = (httpapplication) source;
Httpcontext context = application. context;

Context. response. Write ("application_presendrequestcontent <br> ");

}
Public void dispose ()
{
}

Okay, my hands are exhausted ,:)
Old Rules: consider the following questions carefully:
Are multiple application events in httpmodule related to application events in global. asax? If so, what kind of contact do I have?

Next, we will discuss the construction of httphandler ,:)
However, I am very busy recently. I don't know when to continue.
See you later.

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.