是否可以从 ASP.NET 路由推断站点地图?
一段时间以来,我一直受益于站点地图的优势:
- 外部页面关系。页面不负责定义自己的关系,而是由外部提供商提供。在呈现导航控件时,这消除了页面的许多责任。例如“渲染我的孩子”而不是“我是一个产品列表页面,所以我应该渲染一个产品列表”。
- 可以从任何地方推断页面关系。例如,站点地图页面变得完全自动化,面包屑和顶级导航也是如此。
- 通用导航。可重用控件可用于呈现任何类型页面的链接列表。
到目前为止,我一直在使用 SiteMapProviders 作为路由机制。我已分别将“路由 URL”和“处理程序 URL”存储到每个节点的 Url 和 Key 属性中。即有请求进来,FindSiteMapNode方法被调用,请求被重写为返回节点的key。
这完美,但我知道时代在变化,我们现在有了路由表。
经过一些研究,似乎无法从路由推断页面之间的关系。因此:“无法从路由表推断站点地图”。 (我是对的吗?)
假设这个说法,我如何保持我精彩的站点地图并与时俱进?有没有一种方法可以同时拥有两者而不需要在两者之间重复大量代码?与当前的方法相比,我将从路由表中获得哪些具体收益?
我看过: ASP.NET URL Routing with WebForms - 使用SiteMap,指向 http://chriscavanagh.wordpress.com/2009/05/19/asp-net-webform-routing-with-sitemaps/
但是,该解决方案仅允许 1..1分别在节点和路由之间进行映射。例如,您不能使用此方法让许多产品节点指向单个路由。
I have been benefiting from the advantages of sitemaps for a while now:
- Extrinsic page relationships. Pages are not responsible for defining their own relationships, instead they are supplied by an external provider. This removes a lot of responsibility from the page when it comes to rendering navigation controls. E.g. "Render my children" instead of "I am a product-list page, so I should render a list of products".
- Page relationships can be inferred from anywhere. E.g. Sitemap pages become completely automated, as do breadcrumbs and top-level navigation.
- Generic navigation. Reusable controls can be used to render lists of links to any type of page.
I have, up until now, also been using SiteMapProviders
as a routing mechanism. I've been storing a 'routed URL' and a 'handler URL' into each node's Url and Key properties, respectively. I.e. a request comes in, the FindSiteMapNode method is called, and the request is rewritten to the returned node's key.
This works perfectly, but I am aware times are changing and we now have Routing Tables.
After some research, it appears that relationships between pages cannot be inferred from routes. Ergo: "sitemaps cannot be inferred from a routing table". (Am I right?)
Assuming this statement, how do I keep my wonderful sitemaps and keep with the times? Is there a way of having both without masses of code repetition between the two? What specific gains will I receive from Routing Tables over my current approach?
I have looked at: ASP.NET URL Routing with WebForms - Using the SiteMap, which points to http://chriscavanagh.wordpress.com/2009/05/19/asp-net-webform-routing-with-sitemaps/
However, the solution only allows a 1..1 mapping between nodes and routes, respectively. For example, you cannot have many product nodes point to a single route with this method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么要改变一些最适合你的东西?我建议你根据你提供的信息不做任何改变。我理解使用新的闪亮东西的需求和愿望,但是,你有一些适合你当前的东西需要。
Why change something that works perfectly for you? I recommend you change nothing based on the information you provided. I understand the want and desire to use the new shinny thing, however, you have something that works and fits your current needs.