4

I have Routing working in ASP.NET c# WebForms using Microsoft.AspNet.FriendlyUrls but not for all pages.

Here is an example:

routes.MapPageRoute("List/{Location}/{ZipCode}/", "List/{Location}/{ZipCode}/", "~/List.aspx");

On the above mentioned page (List.aspx) in the page_load there are no values.count in the Page.RouteData.

Page.RouteData.Values.Count == 0

I have another page in the same site with this info matched to it:

routes.MapPageRoute("{Location}/{ZipCode}/{Name}/{LocID}/{ID}/{Code}/", "{Location}/{ZipCode}/{Name}/{LocID}/{ID}/{Code}/", "~/place.aspx");

This page (place.aspx) always shows the correct count of Routes.

While on the List page in debug mode I checked the querystring and location and the ZipCode were there.

So, what might cause Page.RouteData to not show in one page but be available in another?

  • Still having this issue. I went on to use querystring (YUK!) months ago. Today I decided to do another search on google, as I came upon this issue again in the system. I found this thread and I was reading it thinking "WOW same issue as me!" Then I looked and it was my post! Not sure if I could be more specific about the problem. If I click a link that sends me to a page it looks to be working. But not the page_load. – Jeremy Sanzone Aug 01 '14 at 18:06
  • See my answer in this other question: https://stackoverflow.com/a/46365650/14263 – Marco Luglio Sep 22 '17 at 13:17

1 Answers1

9

I am pretty new to url routing, but I think I ran into a similar problem and also found the solution. Have you tried:

routes.MapPageRoute("ListDetails/{Location}/{ZipCode}/", "ListDetails/{Location}/{ZipCode}/", "~/List.aspx");

instead of

routes.MapPageRoute("List/{Location}/{ZipCode}/", "List/{Location}/{ZipCode}/", "~/List.aspx");

?

In my case I had:

routes.MapPageRoute(
    "ImageDelete",
    "Admin/Images/Delete/{nameToKill}",
    "~/Admin/Images.aspx"
);

which showed Page.RouteData.Values always empty.

When I changed it to

routes.MapPageRoute(
    "ImageDelete",
    "Admin/Image/Delete/{nameToKill}", // mind the missing 's'
    "~/Admin/Images.aspx"
);

it worked!

I think the route may not start with the URL of a site that actually exists.

Tillito
  • 7,718
  • 7
  • 34
  • 31
  • 2
    Wow, thanks for telling me something useful that should be in the docs https://msdn.microsoft.com/en-us/library/dd329551(v=vs.100).aspx – karlingen Apr 09 '16 at 07:20