Page.RouteData.Values在一个页面上为空,但在另一页面上不是 [英] Page.RouteData.Values are empty for one page but not another
问题描述
我可以使用Microsoft.AspNet.FriendlyUrls在ASP.NET c#WebForms中使用路由,但是对于所有页面不是.
I have Routing working in ASP.NET c# WebForms using Microsoft.AspNet.FriendlyUrls but not for all pages.
这里是一个示例:
routes.MapPageRoute("List/{Location}/{ZipCode}/", "List/{Location}/{ZipCode}/", "~/List.aspx");
在上述页面(List.aspx)的page_load中,Page.RouteData中没有values.count.
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");
此页面(place.aspx)始终显示正确的路由计数.
This page (place.aspx) always shows the correct count of Routes.
在调试"模式下的列表"页面上,我检查了查询字符串和位置以及ZipCode是否存在.
While on the List page in debug mode I checked the querystring and location and the ZipCode were there.
那么,是什么原因导致Page.RouteData不显示在一个页面中却可以在另一个页面中显示?
So, what might cause Page.RouteData to not show in one page but be available in another?
推荐答案
我对url路由很陌生,但是我认为我遇到了类似的问题,并且也找到了解决方案.您是否尝试过:
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");
代替
routes.MapPageRoute("List/{Location}/{ZipCode}/", "List/{Location}/{ZipCode}/", "~/List.aspx");
?
就我而言,我有:
routes.MapPageRoute(
"ImageDelete",
"Admin/Images/Delete/{nameToKill}",
"~/Admin/Images.aspx"
);
其中显示Page.RouteData.Values始终为空.
which showed Page.RouteData.Values always empty.
当我将其更改为
routes.MapPageRoute(
"ImageDelete",
"Admin/Image/Delete/{nameToKill}", // mind the missing 's'
"~/Admin/Images.aspx"
);
成功了!
我认为路由可能不以实际存在的站点的URL开头.
I think the route may not start with the URL of a site that actually exists.
这篇关于Page.RouteData.Values在一个页面上为空,但在另一页面上不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!