MVC Route detection Component Routing Debugger

Source: Internet
Author: User

Component haacked.com

1. Introducing components into an MVC project

2. Configure route rules

 Public Static voidregisterroutes (routecollection routes) {//routes.            Ignoreroute ("{resource}.axd/{*pathinfo}"); //ignore the About page, you cannot put it behind Maproute, the method is not a route component provides is the method under SYSTEM.WEB.MVC//routes. Ignoreroute ("Home/about");routes. MapRoute ("Default",//Route name                "{Controller}/{action}/{id}",//URL with Parameters                New{controller ="Home", action ="Index", id = urlparameter.optional},//parameter Default value                New{controller=@"^\w+", action=@"^\w+"}            ); Routes. MapRoute ("Filter",//Route name                "{Controller}/{action}/{id}",//URL with Parameters                New{controller ="Filter", action ="Index", id = urlparameter.optional},//parameter Default value                New{controller =@"^\w+", action =@"^\w+" }            ); Routes. MapRoute ("Car",                "Car/{make}/{pro}",                New{controller="Car", action="Index", id=1}                ); Routes. MapRoute ("Archive",                "Archive/{date}",                New{controller ="Blog", action ="Archive" },                New{date=@"^\d{4}-\d{2}-\d{2}" }                ); Routes. MapRoute (" Book",                    "Book/add/{name}",                    New{controller =" Book", action ="ADD" },                    New{httpmethod="Post"}                ); Routes. MapRoute ("Product",                "Product/{*value}",//* means match everything                New{controller="Product", action="Index" }                ); /*dictionary<string, object> defaultrout = new dictionary<string, object> ();            Defaultrout["action"] = "Index";            defaultrout["id"] = 0;            RouteValueDictionary defaultroutevalue = new RouteValueDictionary (defaultrout);            RouteValueDictionary constrainroutevalue = new RouteValueDictionary ();            constrainroutevalue["Controller"] = @ "\w+";            constrainroutevalue["id"] = @ "\d+"; Route route = new Route ("{controller}/{action}/{id}", Defaultroutevalue, Constrainroutevalue, New Mvcroutehandler ());*/        }
View Code

3. Write in Global.asax.cs code

protected void Application_Start ()
{
Arearegistration.registerallareas ();

RegisterRoutes (routetable.routes);
Set to True to indicate that URLs pointing to physical files on disk will also be URL routing processed, such as a normal HTML page
RouteTable.Routes.RouteExistingFiles = true;
RouteDebug.RouteDebugger.RewriteRoutesForTesting (routetable.routes);

}

MVC Route detection Component Routing Debugger

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.