net 4和c#與路由。如何隱藏網址中的ID
我想知道如何從GetRouteUrl(或其他方式)傳遞DataToken中的值。
我的目標是到克里特島的URL,如「mysite.com/category-title」 和傳球(從URL中categoryId
隱藏),但在目標頁面,我想檢索篩選隱藏categoryId
。
目前我嘗試使用DataTokens完成此操作,但沒有結果。
我的問題:
- 如何隱藏在通過路由產生並傳遞隱藏的ID相符的網址的標識?
- 它是我的方法正確的方式(使用DataTokens)?任何更好的主意(請給我一個代碼示例)
感謝您的時間。
<asp:HyperLink runat="server" Text='<%# Eval("Title") %>' NavigateUrl='<%# GetRouteUrl(new { Title = Eval("Title") }) %>'></asp:HyperLink>
public static void RegisterRoutes(RouteCollection routes)
{
// Ex: mysite.com/category-title/
routes.MapRouteCategoryView("myRouteName", "{Title}");
}
我會
public static void MapRouteCategoryView(this RouteCollection routes, string name, string url)
{
// Page Handler map filter to physical path.
PageRouteHandler handler = new PageRouteHandler("~/Cms/FrontEndCms/CategoryView.aspx");
// Create the Route.
CustomRoute myRoute = new CustomRoute(url, handler);
// Setting the Route.
//myRoute.Constraints = new RouteValueDictionary { { "CategoryId", @"\d+" } }; // Only valid Int for Id.
myRoute.DataTokens = new RouteValueDictionary { { "RouteName", name } };
// Add the Route to RouteCollection.
routes.Add(myRoute);
}
嗨,我需要實現的是使用Asp.net路由和不重寫模塊不知道嗎? – GibboK
沒有抱歉,我對路由的接觸非常有限 - 有興趣看到解決方案:S –