Before discussing how to rewrite a website, it is necessary to understand that iis is a mechanism for processing received web requests. When a web request arrives at the iis web server, iis determines how to handle the request based on the requested file suffix. iis can process html pages, images, and static content, or forward the request to the isapi application. After The isapi application processes the request, html static content is generated and returned to iis. Finally, iis sends the request result back to the client. (An isapi application is a set of libraries that can be compiled at any time in the background. Its task is to generate relevant content according to the request .)
For example, if iis receives a pair of info. asp request. It will forward the request to asp. the isapi application calls up and executes the requested asp page, then returns the generated html code to iis, and iis finally sends the content back to the request client. For the asp.net tutorial page, iis transfers the request to the isapi application named aspnet_isapi.dll for processing. The isapi application calls the managed asp.net workflow to process the request, and return the generated html code to the request client.
You can customize iis to map a certain type of extension to a specified isapi application. Figure 1 shows the application configuration dialog box in the iis management tool.
Figure 1. Configured file extension ing
The detailed discussion on how iis manages received requests is beyond the scope of this article. It is important to understand that the asp.net engine is only responsible for processing network requests whose extensions have been correctly configured and mapped to aspnet_isapi.dll.
Use isapi filter to analyze requests
In addition to ing the requested file extension to the corresponding isapi application, iis also performs some other work. For example, iis also takes the initiative to authorize the client user sending the request, and determines whether the authorized user has the access permission to the requested file. During the entire lifecycle of a request, iis processing goes through several stages. iis generates an event at each stage, which can be controlled by the isapi filter in real time.
Like an isapi application, the isapi filter is also an unmanaged code that blocks are installed on web servers. The isapi application is used to respond to a specific file type received. The isapi filter contains the contain code that responds to the events generated by iis, and can even edit the incoming and outgoing data. Isapi also contains many applications, including:
· Authentication and authorization)
· Logging and monitoring)
· Http compression)
· Url rewriting)
The URL rewriting technology implemented by asp.net discussed in this article is the technical content used for URL rewriting based on the isapi filter, however, we still need to discuss whether to use the isapi filter or the technology provided by the asp.net application to implement the URL rewriting technology.
What happens when a request is passed into the asp.net engine?
Before the advent of asp.net, the url rewriting function on the iis web server must be implemented through the isapi filter. Since this guy came out, we can rewrite the url through asp.net, because the interpretation engine of asp.net has great similarities with iis, the similarity is mainly caused by asp.net:
· Events may also occur during the life cycle of the request being processed;
· Any number
HttpmoduleControl the events generated, which is similar to the isapi filter in iis;
· Delegate requested resources
HttphandlerProcessing, which is similar to the isapi application in iis.
Like iis, asp.net sends a status change signal to the processing status of a request during the entire life cycle of the request, causing corresponding events. For example:
BeginrequestEvents are triggered when asp.net starts to respond to client requests;
AuthenticaterequestEvents are triggered after asp.net establishes a user identity.
Authorizerequest,
ResolverequestcacheAnd
EndrequestAnd many other events.
System. web. httpapplicationFor more information, see the class
HttpapplicationSummary.
As mentioned above, you can create an isapi filter and use it for events caused by iis. Similarly, asp.net also provides
HttpmoduleUsed to respond to events triggered by the asp.net engine. An asp.net application can have multiple
Httpmodule. Each time the asp.net engine processes a request, it initializes a configured
HttpmoduleAnd allows it to generate event delegation for events triggered during request processing. In fact, the asp.net engine processes a large number of event delegation calls for each request.
FormsauthenticationmoduleIs embedded with many
HttpmoduleFirst, it checks whether form authorization is used. If yes, it checks whether the user is authorized. If no authorization is available, the user is automatically redirected to the specified logon page. (That is, you can directly record and identify user logon authorization issues in asp.net !)
Recall that in iis, a request is finally transferred to an isapi application for processing. The application processes each request and returns corresponding data. For example, when a client sends a request to access the Classic asp page, iis transfers the request to the asp. dll program for processing. asp. dll executes the asp page content for the request and returns the html code. Asp.net also uses a similar method. The asp.net engine
HttpmoduleAfter initialization, determine and decide to call the corresponding
HttpmoduleTo process the request. (Q: How do I operate httpmodule)
All requests parsed by the asp.net engine are eventually sent to one
HttphandlerOr
Httphandlerfactory(One
HttphandlerSimply return
Httphandler.) The final delegate presents and responds to the requested html encoding and sends it back to iis concurrently. iis then returns the html to the request client.
Asp.net contains many
Httphandler, For example,
PagehandlerfactoryIs used to render the content of the asp.net page,
WebservicehandlerfactoryThe soap data packet used to present the asp.net web service,
TracehandlerUsed to write the html tag of the asp.net Request resource to trace. axd.