Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...