In the previous blog, I explained my understanding of the page lifecycle. I feel that I have not explained it clearly. Therefore, I am here to simulate some processes of the HTTP request processing pipeline, in fact, these events are in the global. asax is embodied. I just want to refine it here for you to better understand the request process of the HTTP request processing pipeline, so that you can process the request in the Asp.net application.ProgramComplete your operations.
InGlobal. asaxThere are several such events
View code
Public ClassGlobal: system. Web. httpapplication {
Protected VoidApplication_start (ObjectSender, eventargs e ){}
Protected VoidSession_start (ObjectSender, eventargs e ){}
Protected VoidApplication_beginrequest (ObjectSender, eventargs e ){}
Protected VoidApplication_authenticaterequest (ObjectSender, eventargs e ){}
Protected VoidApplication_error (ObjectSender, eventargs e ){}
Protected VoidSession_end (ObjectSender, eventargs e ){}
Protected VoidApplication_end (ObjectSender, eventargs e ){}}
In several events, we can do what we want to do. For example, if we rewrite the URL, we can process it in the application_beginrequest event. Permission verification can also be handled in the application_authenticaterequest event, therefore, understanding the page lifecycle can help us to write more perfect applications, such as writing beautiful poems by a poet.
This is my reference.CodeThe simulation of the HTTP request processing pipeline is actually basically a global processing program.Global. asaxAlmost!!
View code
ClassProgram: system. componentmodel. Component
{
Static VoidMain (String[] ARGs)
{
Processpripeline process =NewProcesspripeline ();
Process. startprocess + =NewEventhandler (process_startprocess );
Process. preprocess + =NewEventhandler (process_preprocess );
Process. postprocess + =NewEventhandler (process_postprocess );
Process. endprocess + =NewEventhandler (process_endprocess );
Process. Process ();
}
Static VoidProcess_startprocess (ObjectSender, eventargs E)
{
Console. writeline ("Start processing event processing...");
}
Static VoidProcess_endprocess (ObjectSender, eventargs E)
{
Console. writeline ("Event processing after processing is completed...");
}
Static VoidProcess_postprocess (ObjectSender, eventargs E)
{
Console. writeline ("Event processing after processing...");
}
Static VoidProcess_preprocess (ObjectSender, eventargs E)
{
Console. writeline ("Before processing...");
}
}
View code
Public ClassProcesspripeline: system. componentmodel. Component//Provides the basis implementation of the icomponent interface and enables object sharing between applications.
{
Private Static Readonly ObjectStartevent =New Object();
Private Static Readonly ObjectPrpeprocessevent =New Object();
Private Static Readonly ObjectPostprocessevent =New Object();
Private Static Readonly ObjectEndevent =New Object();
Public EventEventhandler startprocess//Indicates the method to process events that do not contain event data.
{
Add {This. Events. addhandler (startevent, value );}
Remove {This. Events. removehandler (startevent, value );}
}
Public EventEventhandler preprocess
{
Add {This. Events. addhandler (prpeprocessevent, value );}
Remove {This. Events. removehandler (prpeprocessevent, value );}
}
public event eventhandler postprocess
{
Add {This. events. addhandler (postprocessevent, value) ;}
remove {This. events. removehandler (postprocessevent, value) ;}
}
Public eventEventhandlerEndprocess
{
Add {This. Events. addhandler (endevent, value );}
Remove {This. Events. removehandler (endevent, value );}
}
View code
Protected VoidOnstartprocess (eventargs E)
{
If(This. Events [startevent]! =Null)
{
(This. Events [startevent]AsEventhandler )(This, E );
}
}
Protected VoidOnpreprocess (eventargs E)
{
If(This. Events [prpeprocessevent]! =Null)
{
(This. Events [prpeprocessevent]AsEventhandler )(This, E );
}
}
Protected VoidOnpostprocess (eventargs E)
{
If(This. Events [postprocessevent]! =Null)
{
(This. Events [postprocessevent]AsEventhandler )(This, E );
}
}
Protected VoidOnendprocess (eventargs E)
{
If(This. Events [endevent]! =Null)
{
(This. Events [endevent]AsEventhandler )(This, E );
}
}
Public VoidProcess ()
{
Console. writeline ("Start...");
This. Onstartprocess (eventargs. Empty );
Console. writeline ("Begin handle...");
This. Onpreprocess (eventargs. Empty );
Console. writeline ("Handling...");
Console. writeline ("Handle OK");
This. Onpostprocess (eventargs. Empty );
Console. writeline ("OK");
This. Onendprocess (eventargs. Empty );
Console. Read ();
}
}
}