【发布时间】:2012-09-07 13:18:11
【问题描述】:
我正在使用 Web 表单创建 asp.net Web 应用程序,我正在使用注册路由到产品友好的 URL。
以下是 Global.asax.cs 中的代码;
void Application_Start(object sender, EventArgs e) { // 在应用程序启动时运行的代码 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。
谁能告诉我为什么会这样?目前它显示的 URL 像 http:\localhost:5770\Categories\All?Length=11... 这很难理解。
任何提示或帮助???
谢谢
【问题讨论】: