I created a new Web Forms (ASP.NET 4.5) project and I'm trying to get URL routing to work.
RouteConfig.cs
looks like this:
routes.MapPageRoute("surveyhome", "survey/home", "~/Survey.aspx");
routes.MapPageRoute("surveyquestions", "survey/questions/{q}", "~/Survey.aspx");
I have a link that looks like this:
<a href="/survey/questions/1">1</a>
It correctly loads the Survey.aspx
page, so I know it's partly working, but this code (in the codebehind of that page) doesn't work:
if (Page.RouteData.Values["q"] != null)
{
// do something
}
It's always null. Why?
I have tested your code, and no problems for me on ASP.NET 4.0.
Try defining default values, like
routes.MapPageRoute("surveyquestions",
"survey/questions/{q}", "~/Survey.aspx",
false,
new RouteValueDictionary
{ { "q", String.Empty } });
Did that resolve your problem?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With