MVC路由的选择是从上向下去找到,当找到满足条件的路由后会自动跳出.
namespace OA { // Note: For instructions on enabling IIS6 or IIS7 classic mode, // visit http://go.microsoft.com/?LinkId=9394801public class MvcApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "dept", // Route name "dept/{id}", // URL with parameters new { controller = "department", action = "Index", id = "" } // Parameter defaults ); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); } protected void Application_Start() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); } } }
本文转自博客园张占岭(仓储大叔)的博客,原文链接:MVC自定义路由的配置,必须把自己的路由写在前面,如需转载请自行联系原博主。