我正在学习MVC,我需要理解为什么它不能以它应该的方式工作。
下面是我的路由:
public static void RegisterRoutes(RouteCollection routes)
{
// Note: Change the URL to "{controller}.mvc/{action}/{id}" to enable
// automatic support on IIS6 and IIS7 classic mode
//http://localhost/store/category/subcategory/product
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Category", // Route name
"store/{category}/{subcategory}", // URL with parameters
new
{
controller = "Catalog",
action = "Index",
category = "Featured Items",
subcategory = "All Items"
}
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" }, // Parameter defaults
new { controller = @"[^\.]*" } // Parameter constraints
);
}根据我对路由的理解,当我启动web应用程序时,我应该看到以下url:
http:/localhost/store/
我得到的是第二条路线...
此外,如果我将第二个路由更改为"home/{action}/{id}“,它不会捕获任何路由。
你能帮我理解一下这个please..Thanks吗?
发布于 2010-01-13 22:28:29
路由不指定默认URL;默认URL由您的应用程序处理。路由指定当它看到http://localhost/store/bikes/mountain时,它将使用目录控制器。但这并没有指定默认URL;您必须在项目属性中输入该URL。
我建议不要更改第二个url,因为除非您为所有控制器创建分组,否则最好使用默认设置,这样您就可以捕获所有url。对第二个url的更改将要求url为:
匹配HomeController的索引操作的http://localhost/home/home/index,而默认设置捕获http://localhost/home/index...
这有意义吗?
发布于 2010-01-13 22:32:37
https://stackoverflow.com/questions/2057261
复制相似问题