What will happen when a request enters the ASP. NET engine?

Source: Internet
Author: User

Original article: http://space.itpub.net/12639172/viewspace-368974

InASPBefore. NET, you need to use the ISAPI filter to rewrite the URL on the IIS Web server. Because the ASP. NET engine is very similar to IIS, you can use ASP. NET for URL rewriting. The similarities exist because the ASP. NET engine can implement the following functions:

  • An event can be triggered when a request is processed.

  • Allows any number of HTTP modules to process events, which is similar to the ISAPI filter of IIS.

  • Delegate the task of rendering the requested resource to the HTTP handler, which is similar to the ISAPI extension of IIS.

Like IIS, ASP. NET engine triggers an event within the validity period of the request. It sends a signal to indicate that the processing process changes from one state to another. For example, when the ASP. NET engine responds to a request for the first time,BeginRequestThe event is triggered. What is triggered next isAuthenticateRequestEvent that appears when a user ID has been created. (There are also a large number of other events:AuthorizeRequest,ResolveRequestCacheAndEndRequestAnd so on. These events belongSystem. Web. HttpApplicationFor more information, see the technical documentation at the following URL: HttpApplication Class Overview .)

As discussed in the previous section, you can create an ISAPI filter to respond to events caused by IIS. Similarly, ASP. NET provides an HTTP module that responds to events triggered by the ASP. NET engine. You can configure ASP. NET Web applications to have multiple HTTP modules. For each request processed by the ASP. NET engine, each configured HTTP module is initialized and the event handler can be bound to the event triggered during request processing. Note that many built-in HTTP modules are used for each request. One of the built-in HTTP modules isFormsAuthenticationModuleThis module first checks whether form authentication is used. If it is used, it checks whether the user has been authenticated. If not, the user is automatically redirected to the specified logon page.

As mentioned above, the request passed in through IIS will be finally sent to the ISAPI extension, and the task of ISAPI extension is to return the data of the specific request. For example, when requesting a traditional ASP Web page, IIS passes the request to the asp. dll ISAPI extension. The task of this extension is to return the HTML tag of the requested ASP page. The ASP. NET engine uses similar methods. After the HTTP module is initialized, the next task of the ASP. NET engine is to determine which HTTP handler should process the request.

All. the requests passed by the NET engine will eventually arrive at the HTTP handler or HTTP handler Factory (the HTTP handler factory only returns the HTTP handler instance and then uses the instance to process the requests ). The final HTTP handler returns a response, that is, the requested resource. This response will be sent back to IIS, and IIS will return the response to the requesting user.

ASP. NET includes many built-in HTTP processing programs. For example,PageHandlerFactoryUsed to present ASP. NET web pages.WebServiceHandlerFactoryIt is used to present the response SOAP envelope of ASP. NET Web services.TraceHandlerForwardTrace. axdThe HTML tag of the request.

Figure 2 describes how to handle requests to ASP. NET Resources. First, IIS receives the request and schedules the request to aspnet_isapi.dll. Next, the ASP. NET engine initializes the configured HTTP module. At last, the system calls the correct HTTP processing program, presents the requested resources, and returns the generated mark to IIS and the request client.

 

Before ASP. NET, you need to use the ISAPI filter to rewrite the URL on the IIS Web server. Because the ASP. NET engine is very similar to IIS, you can use ASP. NET for URL rewriting. The similarities exist because the ASP. NET engine can implement the following functions:

  • An event can be triggered when a request is processed.

  • Allows any number of HTTP modules to process events, which is similar to the ISAPI filter of IIS.

  • Delegate the task of rendering the requested resource to the HTTP handler, which is similar to the ISAPI extension of IIS.

Like IIS, ASP. NET engine triggers an event within the validity period of the request. It sends a signal to indicate that the processing process changes from one state to another. For example, when the ASP. NET engine responds to a request for the first time,BeginRequestThe event is triggered. What is triggered next isAuthenticateRequestEvent that appears when a user ID has been created. (There are also a large number of other events:AuthorizeRequest,ResolveRequestCacheAndEndRequestAnd so on. These events belongSystem. Web. HttpApplicationFor more information, see the technical documentation at the following URL: HttpApplication Class Overview .)

As discussed in the previous section, you can create an ISAPI filter to respond to events caused by IIS. Similarly, ASP. NET provides an HTTP module that responds to events triggered by the ASP. NET engine. You can configure ASP. NET Web applications to have multiple HTTP modules. For each request processed by the ASP. NET engine, each configured HTTP module is initialized and the event handler can be bound to the event triggered during request processing. Note that many built-in HTTP modules are used for each request. One of the built-in HTTP modules isFormsAuthenticationModuleThis module first checks whether form authentication is used. If it is used, it checks whether the user has been authenticated. If not, the user is automatically redirected to the specified logon page.

As mentioned above, the request passed in through IIS will be finally sent to the ISAPI extension, and the task of ISAPI extension is to return the data of the specific request. For example, when requesting a traditional ASP Web page, IIS passes the request to the asp. dll ISAPI extension. The task of this extension is to return the HTML tag of the requested ASP page. The ASP. NET engine uses similar methods. After the HTTP module is initialized, the next task of the ASP. NET engine is to determine which HTTP handler should process the request.

All. the requests passed by the NET engine will eventually arrive at the HTTP handler or HTTP handler Factory (the HTTP handler factory only returns the HTTP handler instance and then uses the instance to process the requests ). The final HTTP handler returns a response, that is, the requested resource. This response will be sent back to IIS, and IIS will return the response to the requesting user.

ASP. NET includes many built-in HTTP processing programs. For example,PageHandlerFactoryUsed to present ASP. NET web pages.WebServiceHandlerFactoryIt is used to present the response SOAP envelope of ASP. NET Web services.TraceHandlerForwardTrace. axdThe HTML tag of the request.

Figure 2 describes how to handle requests to ASP. NET Resources. First, IIS receives the request and schedules the request to aspnet_isapi.dll. Next, the ASP. NET engine initializes the configured HTTP module. At last, the system calls the correct HTTP processing program, presents the requested resources, and returns the generated mark to IIS and the request client.

Related Article

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.