无法为 MVC 项目设置默认路由
cannot set Default route for MVC project
我无法为我的 MVC 项目设置默认路由。当我 运行 项目时,它转到地址 http://localhost:7555/ and it give the "HTTP ERROR 404" but if I enter the url http://localhost:7555/Default , it goes to the Default page. But I want users to go the Default page even if they dont enter http://localhost:7555/Default.
这是我在 Global.asax
的路线
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{Filtre}", // URL with parameters
new { controller = "Default", action = "Index", Filtre = UrlParameter.Optional } // Parameter defaults
);
我该怎么办?
一般来说,如果您需要此功能,您将拥有一个 HomeController
,它与路由配置一起开箱即用。您选择了 DefaultController
代替 - 因此我们需要稍微改变一下:
routes.MapRoute(
"Default",
"{action}/{Filtre}",
new { controller = "Default", action = "Index", Filtre = UrlParameter.Optional }
);
我无法为我的 MVC 项目设置默认路由。当我 运行 项目时,它转到地址 http://localhost:7555/ and it give the "HTTP ERROR 404" but if I enter the url http://localhost:7555/Default , it goes to the Default page. But I want users to go the Default page even if they dont enter http://localhost:7555/Default.
这是我在 Global.asax
的路线routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{Filtre}", // URL with parameters
new { controller = "Default", action = "Index", Filtre = UrlParameter.Optional } // Parameter defaults
);
我该怎么办?
一般来说,如果您需要此功能,您将拥有一个 HomeController
,它与路由配置一起开箱即用。您选择了 DefaultController
代替 - 因此我们需要稍微改变一下:
routes.MapRoute(
"Default",
"{action}/{Filtre}",
new { controller = "Default", action = "Index", Filtre = UrlParameter.Optional }
);