PageRouteData.Values ​​are empty for one page, but not others

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"); 

The above page (List.aspx) in page_load in the Page.RouteData file does not have .count values.

 Page.RouteData.Values.Count == 0 

I have another page on the same site with relevant information:

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

This page (place.aspx) always shows the correct number of routes.

While on the List page in debug mode, I checked the sequence and location, and there was ZipCode.

So, what could cause Page.RouteData to not appear on one page, but to be available in another?

+4
friendly-url url-routing
source share
1 answer

I am new to URL routing, but I think I ran into a similar problem and also found a solution. You tried:

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

instead

 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 ​​is 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 the site that actually exists.

+8
source share

All Articles