ASP.NET FRAMEWORK depth adventure

xiaoxiao2021-03-06  58

ASP.NET FRAMEWORK depth adventure

Www.chinacs.net 2002-2-15 Chinese C # Technology Station

I remember that there is a good book called Delphi deep adventures, I'm not bad, I will borrow, :)

Here I don't plan to introduce the introduction of ASP.NET. ASP.NET has some except for the name and the ancient ASP. Although you can still find you familiar in ASP.NET. Session, Application, etc., but don't try to paint them with the ancient ASP era session equal sign.

Let's slowly go deep into the core of ASP.NET Framework, see how she is realized, see how she can undertake the reputation of the next generation of Web development technology platform.

This Dongdong has never thought about how many chapters to complete, and there is no need to exist in the form of diary, maybe very short, maybe very long, I will do my best to show ASP.NET Framework in front of it.

If you don't have any understanding of ASP.NET Framework, you can also become an ASP.NET Coding master. If so, you don't have to continue to look down.

Chapter ONE - Process A http request.

We look at the operational mechanism and architecture of ASP.NET Framework. Before you start, we will follow the archaeologists to visit the ancient ASP operation mechanism: When you ask a * .asp file, this http request is first intercepted by the inetinfo.exe process, this INetInfo.exe process is the WWW service process. , Then she will transfer this request to the ASP.DLL process, and the asp.dll process explains the execution of this ASP leaf, and then returns the explanation stream to the client browser.

Turning the head to see how today's ASP.NET Framework handles an HTTP Request. When you ask a * .aspx file, the same HTTP Request will be intercepted by the INetInfo.exe process, after which she judges the suffix of the file, Transfer this request to ASPNET_ISAPI.dll, ASPNET_ISAPI.DLL will send request to the ASPNET_WP.EXE process through a pipe called HTTP PIPELINE. When this HTTP Request enters the ASPNET_WP.EXE process, it will handle this request via HTTPRuntime. After the processing, return the result to the client.

OK, it seems that there is not much improvement, don't worry, we can even understand the details of HttPruntime in ASP.NET Framework. Ok, continue to go deep: After the HTTP Request enters HTTPRuntime, it will continue to enter a Container called HTTPApplication Factory, and she will give an httpApplication to handle the delivery request, this request will enter the following Container: httpmodule-> httphandler factory-> httphandler. When the HTTPHANDLER's ProcessResquest method inside the system is complete, the entire HTTP Request is completed, and the client will get the corresponding stuff.

Squiring ASP.NET Framework processes a process of HTTP Request:

HttpRequest -> inetinfo.exe -> ASPNET_IPI.DLL -> http pipeline -> ASPNET_WP.EXE -> httpauntime -> httpApplication factory -> httpApplication -> httpmodule -> httphandler factory -> httphandler -> httphandler.processRequest () may ask, I know what is the use of this processing process? Of course, it is useful, for example, if you want to intercept a http request in the middle and do your own processing, what should I do? This is the next time we explore the Dongdong, next time we discuss the details of the process. See you lat

(To be continued, welcome to discuss: uESTC95@263.net)

.NET Framework version: 1.0.3705 official version vs.net (C #) version: 7.0.9466 official version

Just finished dinner, just exercise on the keyboard. Then I continue to write this "diary" last time:

How does Chapter TWO - HTTPMODULE work?

We talked back, a HTTP Request from the client was intercepted after the layer was transferred (how to play the skin? Oh) arrived at the HttpModule. HttpModule is similar to an eavesdrower in the ASPNET_WP.EXE process, and people who are slightly common sense will be natural imagination to get the eavesdropper is used, and our httpmodule can be said to be a must-have However, it is necessary to be clear that httpmodule is definitely not a simple listener, it can do more, such as increasing some content to the intercepted request, etc. It is also possible to understand that when an HTTP Request arrives at HTTPModule, the entire ASP.NET Framework system has not made any true processing of this request, but we can pass this HTTP Request to the true request processing center (httphandler) Previously add some information we need in this HTTP Request first, or for some of this HTTP Request information we intercepted, or simply terminate the HTTP Request to meet some conditions in some cases, so that you can play a filter filtering. The role of the device, not just a bug. By reviewing MSDN (do not believe in the QUICKSTARTS web document that .NET SDK comes with the QUICKSTARTS web document, there are no updates in many places, and many things are invalid in the official version), you will find that the system httpmodule implements a name called IHTTPModule. The interface, naturally, it should be thought that as long as our own class can implement the IHTTPModule interface, can you completely replace the system's httpmodule? Completely correct. Before we started your httpmodule class, I will tell you what httpmodule in the system look like. The default httpmodule in the ASP.NET system has the following: system.Web.Caching.Web.SessionState.SessionStateModulesystem .Web.Security.WindowsAuthenticationModuleSystem.Web.Security.FormsAuthenticationModuleSystem.Web.Security.PassportAuthenticationModuleSystem.Web.Security.UrlAuthorizationModuleSystem.Web.Security.FileAuthorizationModule well, we begin to build our own HttpModule course of it. 1) Open vs.net to create a new "Class Library" project, name it MyhttpModule. 2) Quote System.web.dll file

Type in the code area:

Using system; using system.Web;

namespace MyHttpModuleTest {///

/// Description: to implement a custom HttpModule class /// OF: uestc95 /// Contact: uestc95@263.net /// public class MyHttpModule: IHttpModule {/// /// Description: /// OF constructor method: uestc95 /// Contact: uestc95@263.net /// public MyHttpModule () {}

///

/// Description: Init method to achieve IHttpModule interface /// Author: uestc95 /// Contact: uestc95@263.net /// /// HttpApplication parameter of type public void Init (HttpApplication application) {application.BeginRequest = new EventHandler (this.Application_BeginRequest); application.EndRequest = new EventHandler (this.Application_EndRequest);}

///

/// Note: Private method used to do something of their own definition of /// Author: uestc95 /// Contact: uestc95@263.net /// /// Parameters Parameters Parameters /// Event parameter private void application_beginRequest (Object obj, eventargs e) {httpapplication appliment = (httpApplication) OBJ HttpContext Context = Application.Context; httpresponse response = context.response; httpRequest request = context.request;

Response.write ("I am from Application_BeginRequest, :)");

}

///

/// Note: Private method used to do something of their own definition of /// Author: uestc95 /// Contact: uestc95@263.net /// /// Parameters Parameters passing " /// Event parameter private void application_endrequest (object obj, eventargs e) {httpApplication appli = (httpapplication) OBJ HttpContext context = Application.context; httpresponse response = context.response; httpRequest request = context.request; response.write ("I am from Application_endRequest, :)");

}

///

/// Description: Dispose method implemented interface IHttpModule OF ///: uestc95 /// Contact: uestc95@263.net /// public void Dispose () {}}}

3) After compiling in VS.NET, you will get myhttpmodule.dll. 4) Next our job is how to let the ASPNET_WP.EXE process hand over the HTTP Request to this httpmodule? The method is to configure the web.config file. In the web.config file, the following sentence is added: Note to case sensitive, because web.config is an XML The file is sensitive. "Type = myhttpmoduletest.myhttpmodule, myhttpmodule" tells us that the system will handle the HTTP Request request to the MyHttpModuleTest.myHttpModule class in the MyHttpModule.dll file. And this DLL file system will automatically go to / bin subdirectory or System Global Program Buffer (GAC) search. We can put the DLL file we just got in the bin subdirectory. As for the latter, you can do it through the config tool that comes with the official version of the .NET SDK, we don't speak it in detail.

Ok, our httpmodule used to intercept HTTP Request request is complete and assembled, you can try to create a new WebForm in your web project, run it? :) Finally, we assume a place to use this httpmodule. A Site provides free ASP.NET virtual space to everyone, but the agent A site does not want to provide free lunch, he wants to automatically pop up your company's advertisements when you are browsing it. (Like the current WWW. X63.com is the same), I can't always monitor all the pages of all users, and want to add a js code in every page, the workload is unrealistic, and it is not realistic. That end, as long as our httpmodule is completed, all this will be a light and easy, as long as we are captured by each HTTP Request, I will add some JS to him! We mentioned that two events BeginRequest and endRequest are used in the init () method, and these two events are the starting events and events of all events that can be handled in init (), and there are other other things in them. Events can be utilized, you can check the MSDN.

In addition, before I close EditPlus, I need to knock down as follows: I can use RESPONSE, Request, Server, Application in HttpModule, but I can't operate any code related to session! why? Consider it, look back, look at where, and give another question, can you find the system default httpmodule where is configured? looking around.

Next, let's take a look at the HTTPHANDLER section and how to cooperate with HTTPModule.

See you.

(To be continued, welcome to discuss: uESTC95@263.net)

Author: uESTC95ArticleType: Original E-mail: uestc95@263.net.net framework version: 1.0.3705 official version vs.net (c #) version: 7.0.9466 official version

These days have a good appetite, although I don't want to "eat,", but it is good, I hope to add a few pounds. How is the two problems we have finally raised in Chapter TWO, :) First: Why can't I use session? Second: What is the default HTTPModule configured in HTTPModule?

Let's pick the soft persimmon pinch, the answer to the second question is: Configure in the file machine.config, such as C: / Wi in your system file directory.

Nnt / Microsoft.Net / Framework / V1.0.3705 / config / machine.config. Although it is a soft mortal, there is still some Dongdong, which is what is Machine.Config and our common web.config.

Is it? When ASP.NET Framework starts processing an HTTP Request, she will load Machine.config and your request page.

The web.config file in the directory, the configuration inside is the tag, what does it mean to know. If you are in Machine.c

One of your own httpmodule is configured in ONFIG, you can still drop this mapping relationship in "Remove" from the Web.config file. As for the first question, huh, if you have been carefully running the last document but there is no way to study it carefully, you will feel that in httpmodule, you will not use session, :). If you find the last question itself is a "problem", so congratulations, you don't fall into the box box that I deliberately given, and very questioning, :) Today we will explain httpmodule and httphandler The relationship, when today's "diary" is completed, you will find the answer to the first question.

Chapter Three - In-depth httpmodule

We used to handle it to httpmodule and httphandler after an HTTP Request is captured by ASP.NET Framework, but cannot be understood that httpmodule and httphandler are completely independent. In fact, in the process of HTTP Request in httpmodule The control will be handed over to HTTPHANDLER in an event, while the true process is completed in the httphandler, then control the control to httpmodule. That is to say, httpmodule will communicate with HTTPHandler when a request is passed by her request. When will I communicate? This is what mentioned below. We mentioned that the first event in httpmodule is BeginRequest, and the final event is endRequest. If you carefully read the source program given last time, you should find that the parameters we pass in method init () is a httpApplication type, and the two events we have mentioned are one of the events that are delivered. . HttpApplication there are other events, are as follows: application.BeginRequestapplication.EndRequestapplication.PreRequestHandlerExecuteapplication.PostRequestHandlerExecute application.ReleaseRequestStateapplication.AcquireRequestStateapplication.AuthenticateRequestapplication.AuthorizeRequestapplication.ResolveRequestCacheapplication.PreSendRequestHeadersapplication.PreSendRequestContent

It should be noted that Application.PresendRequestHeaders and Application.PresendRequestContent events will continue after EndRequest, and these two events must see what to do from the name of the name. Yes, once the two events have been triggered, the processing of the entire HTTP Request has been completed, and in these two events are the data flow to the client delivery processing. Seeing this, you should have a question: Why didn't you see HTTPHANDLER? Isn't it mentioned that HTTPHANDLER really handles HTTP Request? If you have this question, you are looking carefully, nor you don't want to play this Mo, :). In fact, I will mention it at the beginning, in an HTTP Request in the HTTPModule delivery process, this request is passed to HTTPHandler in a certain moment (exactly the event.). This event is ResolveRequestCache. After this event, httpmodule creates an HTTPHandler's entry instance (ready, :)), but there is no control to hand over, but continue to trigger acquireRequestState and prerequestHandleRexecute event (if you Distinguished. See it, the prefix of the last event is pre, huh, huh. This indicates that the next step is to enter httphandler, which is true, as we guess, after the PrerequestHandleRexecute event, httpmodule will temporarily hand over the HTTPHandler for true HTTP Request processing. The processRequest is executed inside the httphandler to handle the request. After the HTTPHANDLER is processed, the control will be returned to httpmodule, and HttpModule will continue to transfer the HTTP Request to the client until returned to the client. How is it, is it some confusion? Oh, bitter is painless to draw a flow chart, I have drawn a life cycle map of HTTPModule on hand, I can only use characters here to draw ahead of the process, if you want this picture, you can send me Mail, I will give you Mil. HTTP Request's lifecycle map in the entire httpmodule:

Http Request start | HttpModule | HttpModule.BeginRequest () | HttpModule.AuthenticateRequest () | HttpModule.AuthorizeRequest () | HttpModule.ResolveRequestCache () | HttpHandler establish control point | then processes (HttpHandler has been established, then Session available) | HttpModule.AcquireRequestState () | HttpModule.PreRequestHandlerExecute () | HttpHandler into the process HttpRequest | HttpHandler.ProcessRequest () | HttpModule then returns to the processing (HttpHandler end of the life cycle, Session failure) | HttpModule.PostRequestHandlerExecute () | HttpModule.ReleaseRequestState () | HttpModule.UpdateRequestCache () | Httpmodule.PresendRequest Headers () | httpmodule.presendrequestContent () | Return the process back to the client | How to end the entire HTTP Request processing, from above, we should find the last time we propose The answer to the first question. In order to verify the above flow, we can use this following yourself to verify it. Note that we are given below the content, the framework is still the one we give before, and you will add it:

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 EventHandle r (this.Application_PreSendRequestContent));} private void Application_PreRequestHandlerExecute (Object source, EventArgs e) {HttpApplication application = (HttpApplication) source; HttpContext context = application.Context;

Context.Response.write ("Application_PreRequestHandleRexecute
);}

Private void Application_BeginRequest (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpContext context = Application.Context;

Context.Response.write ("Application_BeginRequest
);

private void Application_EndRequest (Object source, EventArgs e) {HttpApplication application = (HttpApplication) source; HttpContext context = application.Context; context.Response.Write ( "Application_EndRequest
");

}

Private void Application_PostRequestHandleRexecute (Object Source, Eventargs E) {httpApplication Application = (httpApplication) Source; httpContext context = Application.Context;

Context.Response.write ("Application_PostRequestHandleRexecute
);

}

Private void Application_releaseRequestState (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpContext context = Application.Context;

Context.Response.write ("Application_ReleaseRequestState
);

}

Private void Application_UpdateRequestCache (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpContext context = Application.Context;

Context.Response.write ("Application_UpdateRequestCache
");

}

Private void Application_AuthenticateRerequest (Object Source, Eventargs E) {httpApplication Application = (httpApplication) Source; httpContext CONTEXT = Application.Context;

Context.Response.write ("Application_AuthenticateRequest
");

}

Private void application_authorizerquest (Object Source, Eventargs E) {httpapplication appli; httpcontext context = Application.Context;

Context.Response.write ("Application_AuthorizeRequest
);

}

Private Void Application_ResolveRequestCache (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpContext CONTEXT = Application.Context;

Context.Response.write ("Application_ResolveRequestCache
");

Private void Application_AcquireRequestState (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpContext context = Application.Context;

Context.response.write ("Application_AcquireRequestState
");

}

Private void Application_PresendRequestHeaders (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpcontext context = Application.Context;

Context.Response.write ("Application_PresendRequestHeaders
");

}

Private void Application_PresendRequestContent (Object Source, Eventargs E) {httpApplication Application = (httpApplication) Source; httpContext CONTEXT = Application.Context;

Context.Response.write ("Application_PresendRequestContent
");

} public void dispose () {}

Ok, your hand is tired, :) Old rules, the following questions carefully: Does the APPLICAX in HTTPModule Contacts in Global.asax? If so, what connection there is?

Next, I will explore the build of Httphandler, :) But I am very busy recently, I don't know when to continue ... try it. See you.

Just finished dinner, just exercise on the keyboard. Then I continue to write this "diary" last time:

How does Chapter TWO - HTTPMODULE work?

We talked back, a HTTP Request from the client was intercepted after the layer was transferred (how to play the skin? " HttpModule is similar to an eavesdrower in the ASPNET_WP.EXE process, and people who are slightly common sense will be natural imagination to get the eavesdropper is used, and our httpmodule can be said to be a must-have However, it is necessary to be clear that httpmodule is definitely not a simple listener, it can do more, such as increasing some content to the intercepted request, etc. It is also possible to understand that when an HTTP Request arrives at HTTPModule, the entire ASP.NET Framework system has not made any true processing of this request, but we can pass this HTTP Request to the true request processing center (httphandler) Previously add some information we need in this HTTP Request first, or for some of this HTTP Request information we intercepted, or simply terminate the HTTP Request to meet some conditions in some cases, so that you can play a filter filtering. The role of the device, not just a bug. By reviewing MSDN (do not believe in the QUICKSTARTS web document that .NET SDK comes with the QUICKSTARTS web document, there are no updates in many places, and many things are invalid in the official version), you will find that the system httpmodule implements a name called IHTTPModule. The interface, naturally, it should be thought that as long as our own class can implement the IHTTPModule interface, can you completely replace the system's httpmodule? Completely correct. Before we started your httpmodule class, I will tell you what httpmodule in the system look like. The default httpmodule in the ASP.NET system has the following: system.Web.Caching.Web.SessionState.SessionStateModulesystem .Web.Security.WindowsAuthenticationModuleSystem.Web.Security.FormsAuthenticationModuleSystem.Web.Security.PassportAuthenticationModuleSystem.Web.Security.UrlAuthorizationModuleSystem.Web.Security.FileAuthorizationModule well, we begin to build our own HttpModule course of it. 1) Open vs.net to create a new "Class Library" project, name it MyhttpModule. 2) Quote System.web.dll file

Type in the code area:

Using system; using system.Web;

namespace MyHttpModuleTest {///

/// Description: to implement a custom HttpModule class /// OF: uestc95 /// Contact: uestc95@263.net /// public class MyHttpModule: IHttpModule {/// /// Description: /// OF constructor method: uestc95 /// Contact: uestc95@263.net /// public MyHttpModule () {}

///

/// Description: Init method to achieve IHttpModule interface /// Author: uestc95 /// Contact: uestc95@263.net /// /// HttpApplication parameter of type public void Init (HttpApplication application) {application.BeginRequest = new EventHandler (this.Application_BeginRequest); application.EndRequest = new EventHandler (this.Application_EndRequest);}

///

/// Note: Private method used to do something of their own definition of /// Author: uestc95 /// Contact: uestc95@263.net /// /// Parameters Parameters Parameters /// Event parameter private void application_beginRequest (Object obj, eventargs e) {httpapplication appliment = (httpApplication) OBJ HttpContext Context = Application.Context; httpresponse response = context.response; httpRequest request = context.request;

Response.write ("I am from Application_BeginRequest, :)");

}

///

/// Note: Private method used to do something of their own definition of /// Author: uestc95 /// Contact: uestc95@263.net /// /// Parameters Parameters passing " /// Event parameter private void application_endrequest (object obj, eventargs e) {httpApplication appli = (httpapplication) OBJ HttpContext context = Application.context; httpresponse response = context.response; httpRequest request = context.request; response.write ("I am from Application_endRequest, :)");

}

///

/// Description: Dispose method implemented interface IHttpModule OF ///: uestc95 /// Contact: uestc95@263.net /// public void Dispose () {}}}

3) After compiling in VS.NET, you will get myhttpmodule.dll. 4) Next our job is how to let the ASPNET_WP.EXE process hand over the HTTP Request to this httpmodule? The method is to configure the web.config file. In the web.config file, the following sentence is added: Note to case sensitive, because web.config is an XML The file is sensitive. "Type = myhttpmoduletest.myhttpmodule, myhttpmodule" tells us that the system will handle the HTTP Request request to the MyHttpModuleTest.myHttpModule class in the MyHttpModule.dll file. And this DLL file system will automatically go to / bin subdirectory or System Global Program Buffer (GAC) search. We can put the DLL file we just got in the bin subdirectory. As for the latter, you can do it through the config tool that comes with the official version of the .NET SDK, we don't speak it in detail.

Ok, our httpmodule used to intercept HTTP Request request is complete and assembled, you can try to create a new WebForm in your web project, run it? :) Finally, we assume a place to use this httpmodule. A Site provides free ASP.NET virtual space to everyone, but the agent A site does not want to provide free lunch, he wants to automatically pop up your company's advertisements when you are browsing it. (Like the current WWW. X63.com is the same), I can't always monitor all the pages of all users, and want to add a js code in every page, the workload is unrealistic, and it is not realistic. That end, as long as our httpmodule is completed, all this will be a light and easy, as long as we are captured by each HTTP Request, I will add some JS to him! We mentioned that two events BeginRequest and endRequest are used in the init () method, and these two events are the starting events and events of all events that can be handled in init (), and there are other other things in them. Events can be utilized, you can check the MSDN.

In addition, before I close EditPlus, I need to knock down as follows: I can use RESPONSE, Request, Server, Application in HttpModule, but I can't operate any code related to session! why? Consider it, look back, look at where, and give another question, can you find the system default httpmodule where is configured? looking around.

Next, let's take a look at the HTTPHANDLER section and how to cooperate with HTTPModule.

See you.

These days have a good appetite, although I don't want to "eat,", but it is good, I hope to add a few pounds. How is the two problems we have finally raised in Chapter TWO, :) First: Why can't I use session? Second: What is the default HTTPModule configured in HTTPModule?

Let's pick the soft persimmon pinch, the answer to the second question is: Configure in the file machine.config, such as C: / Wi in your system file directory.

Nnt / Microsoft.Net / Framework / V1.0.3705 / config / machine.config. Although it is a soft mortal, there is still some Dongdong, which is what is Machine.Config and our common web.config.

Is it? When ASP.NET Framework starts processing an HTTP Request, she will load Machine.config and your request page.

The web.config file in the directory, the configuration inside is the tag, what does it mean to know. If you are in Machine.c

One of your own httpmodule is configured in ONFIG, you can still drop this mapping relationship in "Remove" from the Web.config file. As for the first question, huh, if you are carefully running the last file, but if you don't carefully study it, you will feel

It is indeed possible to use session in httpmodule, :). If you find the last question itself is a "problem", so congratulations, you don't fall into the box box that I deliberately given, and very questioning, :) Today we will explain httpmodule and httphandler The relationship, when today's "diary" is completed, you will find the answer to the first question. Chapter Three - In-depth httpmodule

We used to handle it to httpmodule and httphandler after an HTTP Request is captured by ASP.NET Framework, but cannot be understood that httpmodule and httphandler are completely independent. In fact, in the process of HTTP Request in httpmodule The control will be handed over to HTTPHANDLER in an event, while the true process is completed in the httphandler, then control the control to httpmodule. That is to say, httpmodule will communicate with HTTPHandler when a request is passed by her request. When will I communicate? This is what mentioned below. We mentioned that the first event in httpmodule is BeginRequest, and the final event is endRequest. If you carefully read the source program given last time, you should find that the parameters we pass in method init () is a httpApplication type, and the two events we have mentioned are one of the events that are delivered. . HttpApplication there are other events, are as follows: application.BeginRequestapplication.EndRequestapplication.PreRequestHandlerExecuteapplication.PostRequestHandlerExecute application.ReleaseRequestStateapplication.AcquireRequestStateapplication.AuthenticateRequestapplication.AuthorizeRequestapplication.ResolveRequestCacheapplication.PreSendRequestHeadersapplication.PreSendRequestContent

It should be noted that Application.PresendRequestHeaders and Application.PresendRequestContent events will continue after EndRequest, and these two events must see what to do from the name of the name. Yes, once the two events have been triggered, the processing of the entire HTTP Request has been completed, and in these two events are the data flow to the client delivery processing. Seeing this, you should have a question: Why didn't you see HTTPHANDLER? Isn't it mentioned that HTTPHANDLER really handles HTTP Request? If you have this question, you are looking carefully, nor you don't want to play this Mo, :). In fact, I will mention it at the beginning, in an HTTP Request in the HTTPModule delivery process, this request is passed to HTTPHandler in a certain moment (exactly the event.). This event is ResolveRequestCache. After this event, httpmodule creates an HTTPHandler's entry instance (ready, :)), but there is no control to hand over, but continue to trigger acquireRequestState and prerequestHandleRexecute event (if you Distinguished. See it, the prefix of the last event is pre, huh, huh. This indicates that the next step is to enter httphandler, which is true, as we guess, after the PrerequestHandleRexecute event, httpmodule will temporarily hand over the HTTPHandler for true HTTP Request processing. The processRequest is executed inside the httphandler to handle the request. After the HTTPHANDLER is processed, the control will be returned to httpmodule, and HttpModule will continue to transfer the HTTP Request to the client until returned to the client. How is it, is it some confusion? Oh, bitter is painless to draw a flow chart, I have drawn a life cycle map of HTTPModule on hand, I can only use characters here to draw ahead of the process, if you want this picture, you can send me Mail, I will give you Mil. HTTP Request's lifecycle map in the entire httpmodule:

Http Request start | HttpModule | HttpModule.BeginRequest () | HttpModule.AuthenticateRequest () | HttpModule.AuthorizeRequest () | HttpModule.ResolveRequestCache () | HttpHandler establish control point | then processes (HttpHandler has been established, then Session available) | HttpModule.AcquireRequestState () | HttpModule.PreRequestHandlerExecute () | HttpHandler into the process HttpRequest | HttpHandler.ProcessRequest () | HttpModule then returns to the processing (HttpHandler end of the life cycle, Session failure) | HttpModule.PostRequestHandlerExecute () | HttpModule.ReleaseRequestState () | HttpModule.UpdateRequestCache () | Httpmodule.PresendRequest Headers () | httpmodule.presendrequestContent () | Return the process back to the client | How to end the entire HTTP Request processing, from above, we should find the last time we propose The answer to the first question. In order to verify the above flow, we can use this following yourself to verify it. Note that we are given below the content, the framework is still the one we give before, and you will add it:

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 EventHandle r (this.Application_PreSendRequestContent));} private void Application_PreRequestHandlerExecute (Object source, EventArgs e) {HttpApplication application = (HttpApplication) source; HttpContext context = application.Context; context.Response.Write ( "Application_PreRequestHandlerExecute
");}

Private void Application_BeginRequest (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpContext context = Application.Context;

context.Response.Write ( "Application_BeginRequest
");} 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
);

}

Private void Application_releaseRequestState (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpContext context = Application.Context;

Context.Response.write ("Application_ReleaseRequestState
);

}

Private void Application_UpdateRequestCache (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpContext context = Application.Context;

Context.Response.write ("Application_UpdateRequestCache
");

}

Private void Application_AuthenticateRerequest (Object Source, Eventargs E) {httpApplication Application = (httpApplication) Source; httpContext CONTEXT = Application.Context;

Context.Response.write ("Application_AuthenticateRequest
");

}

Private void application_authorizerquest (Object Source, Eventargs E) {httpapplication appli; httpcontext context = Application.Context;

Context.Response.write ("Application_AuthorizeRequest
);

}

private void Application_ResolveRequestCache (Object source, EventArgs e) {HttpApplication application = (HttpApplication) source; HttpContext context = application.Context; context.Response.Write ( "Application_ResolveRequestCache
");

}

Private void Application_AcquireRequestState (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpContext context = Application.Context;

Context.response.write ("Application_AcquireRequestState
");

}

Private void Application_PresendRequestHeaders (Object Source, Eventargs E) {httpApplication Application = (httpApplication) source; httpcontext context = Application.Context;

Context.Response.write ("Application_PresendRequestHeaders
");

}

Private void Application_PresendRequestContent (Object Source, Eventargs E) {httpApplication Application = (httpApplication) Source; httpContext CONTEXT = Application.Context;

Context.Response.write ("Application_PresendRequestContent
");

} public void dispose () {}

Ok, your hand is tired, :) Old rules, the following questions carefully: Does the APPLICAX in HTTPModule Contacts in Global.asax? If so, what connection there is?

转载请注明原文地址:https://www.9cbs.com/read-118058.html

New Post(0)