Reputation: 73928
net 4 and c# with Routing.
I would like to know how to pass a value in a DataToken from GetRouteUrl (or another ways).
My aim is to crete a Url like "mysite.com/category-title"
and passing (hiding from the URL the categoryId
) but in the destination page I would like retrieve the hidden categoryId
for filtering.
At the moment I try to accomplish this using DataTokens, without result.
My questions:
Thanks for your time on this.
<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}");
}
I would
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);
}
Upvotes: 0
Views: 1044
Reputation: 46047
You could try just encrypting the categoryID in the QueryString.
Upvotes: 1
Reputation: 4069
If you are using the latest version of IIS you can use the URL Rewrite module.
I have usually done something similar to this by using the URL to get the category (or page in my case) by the querystring value the route maps to and then search the database by the route (or path).
Hope this helps.
Craig
Upvotes: 0