I think this topic has been abused. URL Rewrite has already been accepted by many developers. The components and articles about URL Rewrite on the Internet are also endless, but it always makes me feel overwhelmed, so I can't help writing this series of articles. These articles will not talk about the value and significance of URL Rewrite, but will only talk about pure technical content. The article does not provide detailed analysis, but uses my experience to explain this topic from an application perspective. What you already know, what you do not know, what you have already talked about elsewhere, or what you have not said, I hope that the "old things" in this series of articles will not make you feel dull, it also helps you understand ASP. all aspects of URL Rewrite in. NET. If you encounter a problem with URL Rewrite in the future, you can think of these articles, and I may laugh in my dreams.
To fully understand the topics mentioned later in this article, we must briefly understand the communication process between IIS and ASP. NET. Here I will explain the IIS 6 server. As for IIS 5 and IIS 7, the former can be said to have been eliminated, while the latter's "Classic Mode" is similar to IIS 6, while the new "pipeline mode" is actually about ASP. some concepts in NET are deeply integrated with IIS. I believe that if you understand IIS 6 and ASP. NET, there will be no problems in IIS 7 integration mode.
First, let's take a look at a simple one, showing the main steps in IIS from receiving a Request to returning a Response:
1. IIS receives the request;
2. Select an ISAPI to process the request based on the URL characteristics and IIS configuration. Now ASP. net isapi is selected;
3. the ASP. NET execution engine receives the request, so the initialization data is like building various objects );
4. Start to trigger various Pipeline events. Naturally, start with BeginRequest;
5. after multiple Pipeline events, ASP.. NET selects a suitable Handler or HandlerFactory for Processing Based on the configuration for the current request. Of course, except in special cases, for example, the result has been directly output in the previous event and the request has ended );
6. After Handler processing, several Pipeline events are performed to end with an EndRequest;
7. Output Response.
In an ASP. NET application, if you want to perform URL Rewrite, you generally call the RewritePath method of HttpContext in the BeginRequest event to "locate" the request to a target URL. For example, we can rewrite the Application_BeginRequest method in Global. asax to achieve this:
The reason for Rewrite in BeginRequest is that this event was first triggered among all Pipeline events. After "locating" again, some attributes in the current HttpContext also change accordingly, for example, HttpContext. Request. Path ). In this way, the processing logic of the next Pipeline event will be affected. For example, when you need to determine permissions based on the directory, the path after "positioning" is used instead of the request received by ASP. NET. Naturally, the most "significant" Change is the Handler's choice. For example, in the previous example, we relocated the request to "mermerlist. ASP. NET engine will select *. the System. web. UI. the PageHandlerFactory class processes the request.
public class Global : System.Web.HttpApplication{ protected void Application_BeginRequest(object sender, EventArgs e) { HttpContext context = HttpContext.Current; if (context.Request.Path.Equals("/Customers", StringComparison.InvariantCultureIgnoreCase)) { context.RewritePath("~/CustomerList.aspx"); } }} |
There are two concepts that need to be separated when inserting a sentence, namely "ASP. NET Pipeline" and "Web Forms ". Both are important models in ASP. NET, but the difference is very large:
◆ ASP. NET Pipeline: requests received by each ASP. NET application are processed by this "Pipeline. This is an ASP. NET-level model.
◆ Web Forms: When ASP. NET Pipeline is executed, one of the steps is to select an appropriate Handler or HandlerFactory) to process the request. If it is An aspx page, ASP. NET selects the System. Web. UI. PageHandlerFactory class, in which the WebForms model is formed.
In fact, the word "formation" in the above sentence may be inaccurate. Because Web Forms may be an execution engine and model that can be used independently, and System. Web. UI. PageHandlerFactory only utilizes this model. When compiling an ASP. NET application, we can use this model elsewhere as needed.
- Basic Methods for ASP. net ajax framework to call background code
- ASP. NET verification code and Graphic Programming Technology
- ASP. net mvc Tutorial: Create a TaskList Application
- ASP. net mvc video: AJAX