如何处理具有类似路径但具有多个页面处理程序的asp.net webforms中的URL路由

时间:2014-04-24 12:05:08

标签: c# asp.net webforms routing url-routing

具有不同页面处理程序的不同URL无法正常工作,因为它始终从global.asax文件中获取第一个路由处理程序。

Page_ID     Page_Name               Page_url                                    Page_Handler        Parent_Page_ID
1           Home                    home                                        index.aspx              0               
2           Personal                personal                                    Personal.aspx           0               
3           Accounts & Deposits     personal/acounts-deposit                    Personal.aspx           2               
4           Current Account         personal/acounts-deposit/current-account    Personal.aspx           3               
5           Current Gold Accounts   personal/acounts-deposit/gold-account       gold-account.aspx       3               
6           Easy Saver              personal/acounts-deposit/easy-saaver-ac     Personal.aspx           3               
7           Fixed Deposits          personal/acounts-deposit/fixed-account      fixed-account.aspx      3               
8           Loans                   loans                                       loans.aspx              0               
9           Personal Loans          loans/personal-loans                        loans.aspx              8               
10          car Loans               car-loans                                   car-loan.aspx           8     

在我的Menu_Table我可以通过Page_url识别页面,因为它是唯一的。

    routes.MapPageRoute("Personal_Route", "en/{*path}", "~/personal.aspx", false,
        new RouteValueDictionary {
                    { "path", "Page-not-found" },{ "PageName", "Page-not-found" }
                });


    routes.MapPageRoute("Personal_Route2", "en/{*path}", "~/gold-account.aspx", false,
        new RouteValueDictionary {
                    { "path", "Page-not-found" },{ "PageName", "Page-not-found" }
                });

    routes.MapPageRoute("Personal_Route2", "en/{*path}", "~/fixed-account.aspx", false,
        new RouteValueDictionary {
                    { "path", "Page-not-found" },{ "PageName", "Page-not-found" }
                });

以上路线代码默认使用personal.aspx作为所有网址的处理程序

我已经尝试了很长时间,但我无法做到正确。我希望在这方面提供帮助,以便每个页面都由基于Page_url

的正确页面处理程序处理

我希望页面由页面处理程序处理

www.abc.com/personal  ----  (Personal.aspx)
www.abc.com/personal/acounts-deposits -----(Personal.aspx)
www.abc.com/personal/acounts-deposits/current-account -----(Personal.aspx)
www.abc.com/personal/acounts-deposits/current-gold-account ----- (gold-account.aspx)
www.abc.com/personal/acounts-deposits/easy-saver-ac -----(Personal.aspx)
www.abc.com/personal/acounts-deposits/fixed-account ----- (fixed-account.aspx(
www.abc.com/loans ----- (loans.aspx) 
www.abc.com/loans/personal-loans ----- (loans.aspx)
www.abc.com/loans/car-loans ----- (car-loan.aspx)

1 个答案:

答案 0 :(得分:0)

我认为你需要更具体地指定routeUrl参数。

请查看两个msdn页面,如果您还没有:

  1. RouteCollection.MapPageRoute Method
  2. Walkthrough: Using ASP.NET Routing in a Web Forms Application
  3. How to: Define Routes for Web Forms Applications