In the previous section, we're going to explain the various events that pipeline is executing, and we know that in the custom HttpModule init method, we can add our own events, such as the following code:
public class Test:ihttpmodule
{public
void Init (HttpApplication context)
{context
. BeginRequest + = new EventHandler (context_beginrequest);
Context. AuthenticateRequest + + new EventHandler (context_authenticaterequest);
}
void Context_authenticaterequest (object sender, EventArgs e)
{
throw new notimplementedexception ();
}
void Context_beginrequest (object sender, EventArgs e)
{
throw new notimplementedexception ();
}
}
Then the added code, which executes in the pipeline, is executed, and then how is it executed and in what order? Before we get to that, let's look at how these events are exposed in the HttpApplication, and where do you add the events? Reading HttpApplication's source code, we can see that all events are exposed in the form of the following, select two of them to look at:
<devdoc><para>[to be supplied.] </para></devdoc> public
Event EventHandler beginrequest {
Add {addsynceventhookup ( Eventbeginrequest, value, requestnotification.beginrequest);
Remove {removesynceventhookup (eventbeginrequest, value, requestnotification.beginrequest);}
<devdoc><para>[to be supplied.] </para></devdoc> public
Event EventHandler authenticaterequest {
Add {addsynceventhookup ( Eventauthenticaterequest, value, requestnotification.authenticaterequest);
Remove {removesynceventhookup (eventauthenticaterequest, value, requestnotification.authenticaterequest);}
As you can see, all the events are added by calling the Addsynceventhookup method, where the first argument is the value of the Event+ event name, and how the value is derived, we find the declared code:
private static readonly Object eventdisposed = new Object ();
private static readonly Object eventerrorrecorded = new Object ();
private static readonly Object eventpresendrequestheaders = new Object ();
private static readonly Object eventpresendrequestcontent = new Object ();
private static readonly Object eventbeginrequest = new Object ();
private static readonly Object eventauthenticaterequest = new Object ();
private static readonly Object eventdefaultauthentication = new Object ();
private static readonly Object eventpostauthenticaterequest = new Object ();
private static readonly Object eventauthorizerequest = new Object ();
private static readonly Object eventpostauthorizerequest = new Object ();
private static readonly Object Eventresolverequestcache = new Object ();
private static readonly Object Eventpostresolverequestcache = new Object ();
private static readonly Object Eventmaprequesthandler = new Object (); private static ReadOnly Object EventpoStmaprequesthandler = new Object ();
private static readonly Object eventacquirerequeststate = new Object ();
private static readonly Object eventpostacquirerequeststate = new Object ();
private static readonly Object Eventprerequesthandlerexecute = new Object ();
private static readonly Object Eventpostrequesthandlerexecute = new Object ();
private static readonly Object eventreleaserequeststate = new Object ();
private static readonly Object eventpostreleaserequeststate = new Object ();
private static readonly Object Eventupdaterequestcache = new Object ();
private static readonly Object Eventpostupdaterequestcache = new Object ();
private static readonly Object eventlogrequest = new Object ();
private static readonly Object eventpostlogrequest = new Object (); private static readonly Object eventendrequest = new Object ();
Combined with the Add and remove methods, you can boldly guess that these values should be used as a key value, we first read the 2nd argument, and then verify our guess, the 2nd parameter is enumerated type requestnotification, here we guess again, All events should be placed in a unified place, and then be distinguished by this enumeration. Let's take a look at the code for the enumeration class first:
[Flags]
Public enum requestnotification
{
beginrequest = 1,
authenticaterequest = 2,
authorizerequest = 4,
Resolverequestcache = 8,
Maprequesthandler = AcquireRequestState =,
Preexecuterequesthandler =,
Executerequesthandler = 128,
releaserequeststate = 256,
Updaterequestcache =,
logrequest = 1024, endrequest =
2048,
sendresponse = 536870912,
}
Have you found anything yet? Although the flags are used to record for XOR or query, there seems to be less enumeration type here, and the code is carefully checked to see that all events beginning with Post do not appear in this enumeration class. So how are these events declared? Go back to the HttpApplication class to continue viewing the code,
<devdoc><para>[to be supplied.] </para></devdoc> public
Event EventHandler postauthenticaterequest {
Add {addsynceventhookup ( Eventpostauthenticaterequest, Value, Requestnotification.authenticaterequest, true);
Remove {removesynceventhookup (eventpostauthenticaterequest, value, Requestnotification.authenticaterequest, true); }
}