0

I need to provide a pageId on every URL however I don't need the user to see this pageId. For example

http://{domain}/{product-name}/{product-id}/{pageid} <-- I don't want to provide this

I have in my Global.asax:

routes.MapPageRoute("route-name", "path/{productName}/{product-id}", "~/ProductPage.aspx");

Is there some way to configure this route so it has a "hard coded" parameter page id for example something like this ---

routes.MapPageRoute("route-name", "path/{productName}/{product-id}", "~/ProductPage.aspx?pageid=1");

1 Answer 1

0

Is there some way to configure this route so it has a "hard coded" parameter page id

Why yes... yes there is.

MapPageRoute has an overload that accepts a set of defaults for route values.

//Create route and set default values
routes.MapPageRoute(
   "route-name", 
   "path/{productName}/{product-id}", 
   "~/ProductPage.aspx",
   false,
   new RouteValueDictionary{
      {"product-id", 1}
   });

So now if you hit this route without a "product-id" specified, it will always default to 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.