路由映射

//routes.MapRoute方法。这个方法的作用是向系统增加一条路由规则。

namespace MVCDemo

{

// Note: For instructions on enabling IIS6 or IIS7 classic mode, 

// visit http://go.microsoft.com/?LinkId=9394801



public class MvcApplication : System.Web.HttpApplication

{

public static void RegisterRoutes(RouteCollection routes)

{

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");



routes.MapRoute(

"Category", // Route name

"Category/Detail/{name}", // URL with parameters

new { controller = "Category", action = "Detail", name = "" } // 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()

{

RegisterRoutes(RouteTable.Routes);

}

}

}

 


-------------------实例二----------------------------

routes.MapRoute(

"Default",

"{controller}/{action}/{id}",

new { action = "Index", id = "0" },

new { controller = @"^\w+", action = @"^\w+", id = @"^\d+" });

// Archive/2008-05-07

routes.MapRoute(

"BlogArchive",

"Archive/{date}",

new { controller = "Blog", action = "Archive" },

new { date = @"^\d{4}-\d{2}-\d{2}" });

// Car/bmw.abc

routes.MapRoute(

"Car",

"Car/{make}.{model}",

new { controller = "Car", action = "Index" },

new { make = @"(acural|bmw)" });

//必须是提交post url直接回车是get

routes.MapRoute(

"Book",

"Book/Add/{name}",

new { controller = "Book", action = "Add" },

new { httpMethod = "POST" });

//后面所有东西都捕获

routes.MapRoute(

"CatchIt",

"Product/{*values}",

new { controller = "Product", action = "Index" });

 

你可能感兴趣的:(映射)