我已经设法让友好的 url 与我的 cms 一起工作;但是,我想知道的是:使用 asp.net 4.0 路由选项,我如何获得根离开路由?当用户输入关于我们的 www.mysite.com/page_name 时,它会转到 cms.aspx 页面,但其他路径保持不变:
routes.Clear();
// Register a route for Products/{ProductName}
routes.MapPageRoute(
"View Product", // Route name
"Products/{ProductName}", // Route URL
"~/products.aspx" // Web page to handle route
);
// Register a route for Products/{ProductName}
routes.MapPageRoute(
"ShoppingCart", // Route name
"{ShoppingCart}", // Route URL
"~/Basket.aspx" // Web page to handle route
);
// Register a route for Products/{ProductName}
routes.MapPageRoute(
"ShoppingCart", // Route name
"{ShoppingCart}", // Route URL
"~/Basket.aspx" // Web page to handle route
);
// --->> How do i do this
// Register a route for url/{pagename}
routes.MapPageRoute(
"cms", // Route name
"{}", // Route URL
"~/cms.aspx" // Web page to handle route
);
最佳答案
我认为您正在寻找根 Controller 。这将允许您消除 Controller 名称并仅具有: {url}/ Action 听起来您的意图是清理 URL?
关于c# - ASP.NET 路由和 CMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8342238/