Routedebugger, a good helper for ASP. net mvc route debugging

Source: Internet
Author: User

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.

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.