首页 新闻 赞助 找找看

asp.net mvc rounte处理的一个问题

0
悬赏园豆:20 [已关闭问题]

代码
//路由的两种添加方法
第一种
//routes.MapRoute(
// "Default", // Route name
// "{controller}/{action}/{id}", // URL with parameters
// new { controller = "products", action = "Index", id = "" } // Parameter defaults
// , new { id = @"\d?" }
//);

------------------------------------------------------------
第二种 RouteTable.Routes.Add(
new Route("{controller}/{action}/{id}", new MvcRouteHandler())
{
Defaults
= new RouteValueDictionary() { { "controller", "products" }, { "action", "index" }, { "id", 2 } },
Constraints
= new RouteValueDictionary() { { "controller", "products" }, { "action", "index" }, { "id", @"\d?" } },

}

);
并在Application_Start()方法里面添加

RouteTable.Routes.RouteExistingFiles = true;

解释是 

Gets or sets a value that indicates whether ASP.NET routing should handle URLs that match an existing file.

 

那么, 如果使用第一种添加路由的方式,直接启动程序, 由于找不到 Default.aspx控制器,会出现黄页

而,使用第二种添加路由的方式,启动程序, 会自动选择默认设置好的控制器和方法(这里是products/index)

 

请问这两种添加路由规则的方法有什么区别?为什么会出现这种情况

MyCoolDog的主页 MyCoolDog | 初学一级 | 园豆:95
提问于:2009-12-08 09:34
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册