MvcSitemapProvider-在网址解析器中添加要忽略的值 [英] MvcSitemapProvider - Add value to ignore in url resolver

查看:89
本文介绍了MvcSitemapProvider-在网址解析器中添加要忽略的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网址列表中有一个链接,其中包含动态ID,即

I have a link in my url-list which includes dynamic ids, i.e.

/controller/action/id

/controller/action/id

例如,当前不需要为每个页面都拥有自己的面包屑,最好是跳回索引操作面包屑或简单地设置父解析URL.

Currently it's not needed to have for each of my pages an own breadcrumb for example, better would be to jump back to the index action breadcrumb or to simple set a parent resolving url.

有没有简单的解决方案或任何提示来解决此问题?

Is there a simple solution or any tips how to solve this problem?

提前谢谢

推荐答案

有两种方法可以在MvcSiteMapProvider中使用"id"或任何其他路由值.

There are 2 ways to use an "id" or any other route value with MvcSiteMapProvider.

1..为每个"id"创建一个节点(通常使用

1. Create a node for each "id" (usually this is done with a DynamicNodeProviderBase implementation). This gives you a 1-to-1 relationship between the "id" value and the node. Use this method if you have < 10,000 nodes and you want them all indexed by search engines.

<mvcSiteMapNode title="Product 1" controller="Product" action="Details" id="1"/>
<mvcSiteMapNode title="Product 2" controller="Product" action="Details" id="2"/>
<mvcSiteMapNode title="Product 3" controller="Product" action="Details" id="3"/>

2..通过在节点上设置preparedRouteParameters ="id",创建一个节点以匹配所有"id"值.这将使您在路由参数名称"id"(该值无关紧要)与节点之间进行一对一的重建.这仅适用于面包屑路径;对于Menu,SiteMap和/sitemap.xml端点,您将需要使用可见性提供程序以及 SiteMapTitle 属性以修复UI的显示.将这种方法用于编辑数据的管理页面,搜索引擎将永远不会看到它们.

2. Create a single node to match all "id" values by setting preservedRouteParameters="id" on the node. This will give you a 1-to-1 relastionship between the route parameter name "id" (the value doesn't matter) and the node. This only works for the breadcrumb trail; for the Menu, SiteMap, and /sitemap.xml endpoints, you will need to use a visibility provider as well as a SiteMapTitle attribute to fix the display of the UI. Use this method for administration pages that edit data and will never be seen by search engines.

<mvcSiteMapNode title="Product 1" controller="Product" action="Details" preservedRouteParameters="id"/>

请注意,如果您有多个参数,也可以在同一节点上结合使用这两种技术.例如,如果您具有搜索引擎永远不需要知道的用户特定的"userId"参数,则可以减少节点数(通常,您需要为[所有"id"值] X [全部提供一个节点] ["userId"值]-也就是说,总匹配"userId",但总索引所有索引.SiteMap中的总节点数将等于所有潜在值组合的乘积.

Note that you can also combine both techniques on the same node if you have multiple parameters. If, for example you have a user specific "userId" parameter that search engines will never need to know about, you can reduce the number of nodes (normally you would need to provide a node for [all "id" values] X [all "userId" values] - that is, the total node count would equal the product of all of the potential value combinations) in the SiteMap by always matching the "userId", but still index all of the products.

<mvcSiteMapNode title="Product 1" controller="Product" action="Details" id="1" preservedRouteParameters="userId"/>
<mvcSiteMapNode title="Product 2" controller="Product" action="Details" id="2" preservedRouteParameters="userId"/>
<mvcSiteMapNode title="Product 3" controller="Product" action="Details" id="3" preservedRouteParameters="userId"/>

还要注意,您不必使用XML来使用这些技术-当以其他方式声明节点时,它们也可以工作.

Note also that you don't have to use XML to use these techniques - they also work when declaring nodes in other ways.

在我的博客上有完整的文章介绍了上述每种技术,并提供了可下载的工作示例:

There is a complete article that describes each of these techniques with downloadable working samples on my blog: How to Make MvcSiteMapProvider Remember a User's Position.

这篇关于MvcSitemapProvider-在网址解析器中添加要忽略的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆