I’m using MapPageRoute (ASP.NET 4) for supporting friendly urls in a multi language web site.
I want to be able to pass additional parameters along with the ones defined in the MapPageRoute.
In the example above, I need to determine the requested language according to the URL:
(if it is “Accessories”, the page should be in English, if it is “Accessoires” – the page should be in French):
routes.MapPageRoute(
"Accessory fr",
"Accessoires/{accessory_name}",
"~/Accessory.aspx?lang=fr"
);
routes.MapPageRoute(
"Accessory en",
"Accessories/{accessory_name}",
"~/Accessory.aspx?lang=en"
);
So, no problem with the requested accessory name, it is read by using Page.RouteData.Values["accessory_name"], but how can I read the lang parameter ?
I cannot use Request["lang"] since it doesn’t give me the requested results.
Somehow, the ?lang=xx is not taken .
Any other idea, how can I pass additional parameter, assuming this parameter is not found explicitly in the URL ?
If what you want is to pass additional parameters to your route handler(page), you can set DataTokens property,
You could access this in your handler(page),
Check msdn,
Route.DataTokens Property