這是我能夠實現我認爲你的要求。
// Portal Sections
routes.MapRoute("Home",
"",
new { controller = "Home", action = "Index" },
new[] { "Myapp.Portal.Controllers" });
routes.MapRoute("About",
"about",
new { controller = "Home", action = "About" },
new[] { "Myapp.Portal.Controllers" });
routes.MapRoute("Features",
"features",
new { controller = "Home", action = "Features" },
new[] { "Myapp.Portal.Controllers" });
routes.MapRoute("Help",
"help",
new { controller = "Help", action = "Index" },
new[] { "Myapp.Portal.Controllers" });
routes.MapRoute("Knowledgebase",
"help/kb",
new { controller = "Help", action = "Knowledgebase" },
new[] { "Myapp.Portal.Controllers" });
我可以訪問
- mysite.com
- mysite.com/about
- mysite.com/features
- mysite.com/help
- mysite.com/ help/kb
但訪問是不可
- mysite.com/home/about
- mysite.com/home/features
希望這有助於:)
這是非常相似的問題我問了一天:http://stackoverflow.com/questions/9974402/301-redirect-original-url-request-to-routed-url。我不是說它是重複的,因爲我認爲它有些不同,但我也有興趣知道這個答案。 – Curt 2012-04-04 16:11:35
我很好奇你爲什麼不希望從多個端點訪問路由。 – 2012-04-04 16:14:29
也許使用nuget中的'AttributeRouting'軟件包,以便您可以明確定義您的所有路線...... – dotjoe 2012-04-04 16:18:47