ASP.NET路由和CMS

时间:2011-12-01 13:37:00

标签: c# asp.net vb.net

我已经设法让友好的网址与我的cms合作;但是,我想知道的是:使用asp.net 4.0路由选项,我如何让root离开路由?当用户输入www.mysite.com/page_name(即aboutus)时,它会转到页面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
        );

1 个答案:

答案 0 :(得分:1)

我认为你正在寻找一个根控制器。这将允许您消除控制器名称,只需: {URL} /动作 听起来你的目的是清理URL?

请参阅:Having trouble with a simple MVC route