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?

4

1 回答 1

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"].
于 2012-05-25T18:30:59.517 回答