MVC series Learning (14)-routing rules and route debugging tools, mvc debugging tools

Source: Internet
Author: User

MVC series Learning (14)-routing rules and route debugging tools, mvc debugging tools

1. This learning code is relatively simple, that is, add a route information in the routing configuration file, and add a corresponding controller and view.

There are two routing matching rules, a Kim controller, which has an Index method and a corresponding Index view.

2. Start configuring RouteDebugger

2.1 Download assembly

RouteDebugger-2.1.3.0

2.2 add reference and configure RouteDebugger

In the web. config file under the root directory of the website, add the following statement to the <deleetting> </deleetting> node:

Public class RouteDebuggerHttpModule: IHttpModule {// Methods public void Dispose () {} public void Init (HttpApplication context) {context. endRequest + = new EventHandler (RouteDebuggerHttpModule. onEndRequest); context. beginRequest + = new EventHandler (RouteDebuggerHttpModule. onBeginRequest);} private static void OnBeginRequest (object sender, EventArgs e) {if (RouteTable. routes. last <RouteBase> ()! = DebugRoute. singleton) {RouteTable. routes. add (DebugRoute. singleton) ;}} private static void OnEndRequest (object sender, EventArgs e) {new DebugHttpHandler (). processRequest (HttpContext. current );}}

Originally in RouteDebugger, two events were added to the request pipeline in the init () method, that is, the first pipeline handles the event BeginRequest and the last pipeline handles the event EndRequest, no wonder the whole request can be monitored

5. Expansion: Use of routing rules

6. Route Constraints

If you follow the code above, you will be confused. Because sometimes, you want this request to eventually match route Rule A. As A result, it matches route rule B. Next we will solve this problem.

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.