c# - ASP.NET 路由和 CMS

标签 c# asp.net vb.net

我已经设法让友好的 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?

参见:Having trouble with a simple MVC route

关于c# - ASP.NET 路由和 CMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8342238/

相关文章:

c# - 函数参数中的列表文本框

c# - 如何在 c#.net 中制作来电显示

vb.net - 使用 VB.Net 中的 HtmlAgilityPack 检查元素是否具有特定属性

c# - 变更通知的最佳模式(事件或委托(delegate))

c# - 更改 MS Excel 2003 的背景

c# - 在本地谷歌地图上渲染 kml 文件?

mysql - 访问google map 数据库

asp.net - 为 session 值的键名创建一个枚举是个好主意吗?

c# - 防止.net ide在中断时跳转到当前执行行

c# - 使用 Task.ContinueWith 创建执行队列?