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?

1 Answer 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"].
Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.