2012-09-14 38 views
3

我使用web窗體創建asp.net web應用程序,我使用註冊路由來產品友好的URL。在asp.net 4.0應用程序中錯誤Page.GetRouteUrl()。任何URL路由幫助

以下是Global.asax.cs中的代碼;

空隙的Application_Start(對象發件人,EventArgs的) { ,關於應用程序的啓動 的RegisterRoutes(RouteTable.Routes)運行//代碼; }

void RegisterRoutes(RouteCollection routes) 
    { 
     // Register a route for Categories/All 
     routes.MapPageRoute(
      "All Categories",  // Route name 
      "Categories/All",  // Route URL 
      "~/AllCategories.aspx" // Web page to handle route 
     ); 

     // Route to handle Categories/{CategoryName}. 
     // The {*CategoryName} instructs the route to match all content after the first slash, which is needed b/c some category names contain a slash, as in the category "Meat/Produce" 
     // See http://forums.asp.net/p/1417546/3131024.aspx for more information 
     routes.MapPageRoute(
      "View Category",    // Route name 
      "Categories/{*CategoryName}", // Route URL 
      "~/CategoryProducts.aspx"  // Web page to handle route 
     ); 
     // Register a route for Products/{ProductName} 
     routes.MapPageRoute(
      "View All Product",   // Route name 
      "Products", // Route URL 
      "~/ViewProducts.aspx"  // Web page to handle route 
     ); 


     // Register a route for Products/{ProductName} 
     routes.MapPageRoute(
      "View Product",   // Route name 
      "Product/{ProductName}", // Route URL 
      "~/ViewProduct.aspx"  // Web page to handle route 
     ); 


     // Register a route for Products/{ProductName} 
     routes.MapPageRoute(
      "Add Product",   // Route name 
      "NewProduct", // Route URL 
      "~/AddProduct.aspx"  // Web page to handle route 
     ); 


    } 

現在,在一個頁面上,當我把

 lnkNewProduct.NavigateUrl = Page.GetRouteUrl("Add Product"); 

它產生錯誤的href網址,當我運行該項目。

任何人都可以請告訴爲什麼會發生這種情況?目前它顯示的URL如http:\ localhost:5770 \ Categories \ All?Length = 11 ...這很難理解。

任何提示或幫助?

感謝

回答