不能为MVC项目默认路由 [英] cannot set Default route for MVC project
问题描述
我不能为我的MVC项目设置缺省路由。当我运行该项目,这是不言而喻的地址的http://本地主机:7555 / 以及它带来的HTTP错误404,但如果我输入该网址的http://本地主机:7555 /默认,它关系到默认页。但是,我希望用户去,即使他们不进入 HTTP默认页面://本地主机:7555 /默认
I cannot set the Default Route for my MVC project. When I run the project, it goes to the address 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中路由
here is my Route in 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
而不是 - 所以我们需要工作,它有点不同:
Generally if you want this functionality you would have a HomeController
that just works out of the box with the route config. You've chosen instead to have DefaultController
instead - so we need to work it a little differently:
routes.MapRoute(
"Default",
"{action}/{Filtre}",
new { controller = "Default", action = "Index", Filtre = UrlParameter.Optional }
);
这篇关于不能为MVC项目默认路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!