What is routedebugger?
In ASP. NET MVCProgramRouting (route) is a very core concept. It can be said that it is the entry of the MVC program, because every HTTP request must go through route computing and then match the corresponding controller and action. Generally, our routes are registered in global. asax. in the registerroutes method in the CS file, routes are matched from top to bottom. Therefore, custom (high-priority) routes must be placed before the default (general) routes. However, how can we ensure that all the routes are correct or there are no duplicates? Routedebugger is such an analysis tool.
Install
You can use nuget to easily install routedebugger, right-click the project and choose "manage nuget packages"-"online" enter "routedebugger" and then "Install ", alternatively, enter "Install-package routedebugger" in "Package Manager Console" to install the package. Because nuget is sometimes inexplicably walled, I uploaded a compressed file: routedebugger 2.1.3.
Note: routedebugger 2. x corresponds to. net4.0 and mvc3. For earlier versions, see ASP. net routing debugger of Phil haack.
Use
After successful installation, you can see that the project references "routedebugger", and then? Then press F5 to run the program and you will see the effect. Yes, you don't even need to configure any rows.Code! This is because the Microsoft. Web. Infrastructure Assembly added to. net4.0 allows Dynamic Registration of httpmodule. routedebugger appends formatted route debugging information to each request. For projects before. net3.5 and mvc3, if you want to use routedebugger, you also need to register in application_start:
?
1
2
3
4
5
Protected Void Application_start (Object Sender, eventargs E)
{
Registerroutes (routetable. routes );
Routedebug. routedebugger. rewriteroutesfortesting (routetable. routes );
}
From the output of the browser, we can see the detailed route matching information. Which routes can be successfully matched by the current request.
Note: The {* catchall} route is automatically added by the routdebugger, so that even if no route matches successfully, the corresponding route information is displayed, instead of 404 (however, I found that 404 was returned for the illegal URL in my local test. Someone raised this question in Phil haack's blog but was not answered ).
Disable routedebugger
When routedebugger is used, you will find that the route information is included at the end of each page. To disable this function, enable Web. config:
Set Value = "false" after routedebugger: enabled to disable the routedebugger mode.