And the role of 3.httphandler httpmodule variety and how it works?

  First, be appreciated that the ASP.NET request processing pipeline based model, this channel model is composed of a plurality HttpModule and HttpHandler, ASP.NET http request is sequentially transmitted to the respective pipeline HttpModule, HttpHandler eventually processed, the processing is completed after again through the HTTP pipeline module, the results returned to the client. We can process the request to intervene in each HttpModule in.

  httpmodule Introduction

  httpmodule main role is to register custom events to httpApplication object, and so on may be authorized to verify

  1. All httpmodule are realized System.Web.IhttpModule Interface

  2. There are two override methods:

    (1) Init method: automatic call system initialization time, this method allows HTTP module to register your own event handler to HttpApplication object events.
    (2) Dispose method: This method gives the opportunity to perform HTTP module to clean up before the object is garbage collected. This method is generally without writing code.

  3. Allow the registration of the following events:

  1. AcquireRequestState  ready to receive the current status dialogue HTTP request when ASP.NET runtime when triggered this event.
  2. AuthenticateRequest  ready to authenticate users when ASP.NET runtime when triggered this event. 
  3. AuthorizeRequest  ready to authorized users from accessing resources when ASP.NET runtime when triggered this event. 
  4. BeginRequest  reception when ASP.NET runtime when a new HTTP request triggered this event. 
  5. Disposed  This event is raised when a complete ASP.NET HTTP request processing. 
  6. EndRequest  the contents of the response before sending a client to trigger this event. 
  7. Error  when unhandled exception occurs during the processing of HTTP request triggered this event. 
  8. PostRequestHandlerExecute  This event is raised when the end of the implementation of the HTTP handler. 
  9. PreRequestHandlerExecute  This event is raised before the start of the implementation of the ASP.NET HTTP request processing program. After this event, ASP.NET forwards the request to the appropriate HTTP handler. 
  10. PreSendRequestContent  in ASP.NET content before sending the response to the client to trigger this event. This event allows us to change the response content before the content reaches the client. We can use this event to add to the page output for the contents of all pages. For example generic menu, header information or feet. 
  11. PreSendRequestHeaders  trigger this event before sending HTTP response header information to the client in ASP.NET. Before header information reaches the client, this event allows us to change its contents. We can use this event to add custom data in the cookie and header information. 
  12. ReleaseRequestState  when the end of the search, some ASP.NET request handler executed when triggered this event. 
  13. ResolveRequestCache  we caused this event to determine whether you can use the content returned from the output buffer to the end of the request. How to set the time depending on the output buffer of the Web application. 
  14. UpdateRequestCache  when finished with the current ASP.NET HTTP request processing, and output content when ready to add to the output buffer, triggering this event. Depending on how the Web application output buffer is set.

  4. To use must be registered in the custom httpmodule Web.Conofig, the registration code is as follows

   <httpModules>
           <add name="TestModule" type="命名空间.类名"></add>
         </httpModules> 

  Introduction httphandler

  httphandler main role is to deal with the center of the HTTP request, the server really make a client requests a page compilation and execution, and additional information in the HTTP request information flow is returned to the HttpModule again after treatment

  1. All httphandler are achieved IHttpHandler interface declaration

  2.HttpHandler with different HttpModule, HttpHandler Once you define your own classes, then the relationship HttpHandler of its system will be "covered" relationship

  3. must be registered in Web.Config configuration file, the registration code is as follows

  <httpHandlers>
       <add verb="*" path="*" type="命名空间.类名"></add>
      </httpHandlers> 

  4. realize their business process logic ProcessRequest

  

Guess you like

Origin www.cnblogs.com/Zyj12/p/10973052.html