0

I'm trying out .net 4.0 routing with Webforms for the first time and I'm running into a problem. The page I'm routing to is looking for a querystring based on the route url.

For Example:

routes.MapPageRoute(
"Rule2",                               // Route name
"news/{day}/{month}/{year}/{.*}.aspx", // Route URL
"~/mynews.aspx"                        // Web page to handle route
);

I want the final route to send mynews.aspx?story={day}{month}{year}. But I can't figure it out. I found this to be some help http://msdn.microsoft.com/en-us/library/cc668177.aspx but request.querystring("story") gives me nothing.

Any words of wisdom?

invisiblestupid
  • 109
  • 1
  • 7

1 Answers1

2

Normally you wouldn't have 'aspx' in the route URL because you'd want a user friendly one. So, the route URL would be "news/{day}/{month}/{year}/{.*}" and a valid URL 'news/25/5/2012', for example.

Then to access the data you use

string day = (string) RouteData.Values["day"].
graham mendick
  • 1,839
  • 1
  • 17
  • 15
  • Which makes sense. So I can no longer use querystrings and will have to change the code in the website look for routedata values and not querystring. Sigh...I guess I'm just too old school and don't cotton to these new-fangled ideas. Thanks for your help. – invisiblestupid May 25 '12 at 19:01
  • Well, Graham answered my question. I ended up going a slightly different route but he gets props for getting me where I need to go. Thank you. – invisiblestupid May 30 '12 at 14:52