Controller-URL Routing HTTP module (i)

Source: Internet
Author: User

The URL routing HTTP module handles the URLs that check inbound requests and dispatches them to the most logical processor. The URL routing HTTP module also replaces the old version of the ASP. Net URL rewrite feature. At the core, URL rewriting consists of the connection request, the transformation of the original URL, and the instructions for the HTTP runtime environment to handle a "most likely relevant but differentiated" URL.

Override URL Overrides

URL rewriting works if we need to make tradeoffs in terms of routing readability, search engine friendliness, and the need to programmatically handle a number of URLs. For example, we consider the following URLs:

The News.aspx page contains some logic to retrieve, format, and display the corresponding news. The retrieval of a particular news number is provided through parameters in the query string. As a developer, it is not easy to implement such a page, first get the parameters of the query string, then execute the query, and finally create the HTML page, but you are not very easy to remember the URL address.

However URL rewriting can help you in two ways. First, it makes it possible for developers to use a generic front-facing page, such as news.aspx, to show the relevant content. Second, it makes it possible for users to access more friendly URLs, which are mapped programmatically to URLs that are less sensitive but more manageable. Simply put, URL rewriting exists to reduce the coupling of the requested URL to the physical page that handles the request.

In the last version of ASP. NET 4 Web Forms, you can use URL rewriting to match inbound URLs to other URLs rather than using HTTP 302 redirection. Instead, in ASP. NET MVC, the goal of URL routing is to map the inbound URL to the corresponding controller and the corresponding behavior method.

Note: The URL routing module was originally developed as a component of ASP. But it is now a native part of the ASP. As mentioned above, it provides services to both ASP. NET MVC and ASP. NET Web Forms applications, although And then through a slightly different API.

Routing requests

What exactly happened when a request arrived at IIS?

The URL routing module intercepts any requests that cannot be processed by IIS for the application. If the URL points to a physical file (for example, an ASPX file), the routing module ignores the request unless the URL is specifically configured. The request then falls on the traditional ASP. NET mechanism and is processed, which is page handler.

Instead, the URL routing module attempts to match the request URL with the application-defined route Ching. If the match succeeds, the request enters the ASP. NET MVC space and is processed. If no match succeeds, the request is handled by the standard ASP. NET runtime and is likely to cause an HTTP 404 error to be displayed.

Finally, only those requests that match a pre-defined URL pattern can enter the ASP runtime. All of these requests will be routed to a common HTTP handler, which can instantiate a controller class and invoke a well-defined method in it. Then, the method in this controller, in turn, selects a view component and generates a response.

URL Routing Module Internal structure

Based on the implementation principle, the URL routing engine is an HTTP module that encapsulates the Postresolverequestcache event. This event is started immediately if there is no response to the request in the ASP.

The HTTP module matches the requested URL with a user-defined URL route, sets the HTTP context, and processes the request using the ASP. NET MVC standard HTTP handler. As a developer, we are not likely to deal directly with the URL routing module. This module is provided directly by the system and you do not need to configure it in the appropriate form. Then, you are obligated to provide the appropriate route for your application, and this will be used by the routing module.

Controller-URL Routing HTTP module (i)

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: 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.