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 .)
Zheng
As discussed in the previous section, you can create an ISAPI filter to respond to events caused by IIS. Similarly, ASP. NET provides the HTTP module, which can respond
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 engine will initialize each configured HTTP
Module, and allows the event handler to be bound to events 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.
For example
As described above, by using IIS, incoming requests will be finally sent to the ISAPI extension, and the ISAPI extension task is to return the data of a specific request. For example
When a Web page is accessed, IIS sends the request to the ASP. dll ISAPI extension. The task of this extension is to return the HTML tag of the requested ASP page. ASP. NET
The 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 connections
Requests passed through the ASP. net engine will eventually arrive at the HTTP processing program or HTTP processing program Factory (the HTTP processing program factory only returns HTTP
And then use the instance to process requests ). The final HTTP handler returns a response, that is, the requested resource. This response will be sent back to IIS, and then IIS
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
Aspnet_isapi.dll. Next, the ASP. net engine initializes the configured HTTP module. Finally, the correct HTTP
Processes and presents the requested resources, and returns the generated tags to IIS and the request client.
In
Before ASP. NET, you must use the ISAPI filter to rewrite the URL on the IIS web server. Because ASP. NET engine and IIS
Therefore, you can use ASP. NET to rewrite the URL. 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 .)
Zheng
As discussed in the previous section, you can create an ISAPI filter to respond to events caused by IIS. Similarly, ASP. NET provides the HTTP module, which can respond
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 engine will initialize each configured HTTP
Module, and allows the event handler to be bound to events 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.
For example
As described above, by using IIS, incoming requests will be finally sent to the ISAPI extension, and the ISAPI extension task is to return the data of a specific request. For example
When a Web page is accessed, IIS sends the request to the ASP. dll ISAPI extension. The task of this extension is to return the HTML tag of the requested ASP page. ASP. NET
The 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 connections
Requests passed through the ASP. net engine will eventually arrive at the HTTP processing program or HTTP processing program Factory (the HTTP processing program factory only returns HTTP
And then use the instance to process requests ). The final HTTP handler returns a response, that is, the requested resource. This response will be sent back to IIS, and then IIS
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
Aspnet_isapi.dll. Next, the ASP. net engine initializes the configured HTTP module. Finally, the correct HTTP
Processes and presents the requested resources, and returns the generated tags to IIS and the request client.