Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

asp.net - Page.RouteData.Values are empty for one page but not another

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...