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.