【发布时间】:2014-02-08 10:17:09
【问题描述】:
我使用 MvcSiteMapProvider 来为我们的站点实现动态站点地图。该站点拥有不断更新的文章集,每篇文章都表示为不同的页面。因此,我们使用 MvcSiteMapProvider 来动态生成 sitemap.xml。然而,问题是我们已将图像添加到文章中,我们希望将其添加到 sitemap.xml 以便它们也可以被索引。
我需要实现的是生成一个类似于将图像网址添加到站点地图的结构,即:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>http://example.com/sample.html</loc>
<image:image>
<image:loc>http://example.com/image.jpg</image:loc>
</image:image>
<image:image>
<image:loc>http://example.com/photo.jpg</image:loc>
</image:image>
</url>
</urlset>
目前我的DynamicNode生成代码是这样的
public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
List<Article> articles = new List<Article>();
using(siteMapHelperDB db = new siteMapHelperDB())
{
articles = db.GetArticleSiteMapNodes();
}
foreach(Article item in articles)
{
var dynamicNode = new DynamicNode();
dynamicNode.Title = item.urlName; // URL Friendly title
dynamicNode.RouteValues.Add("id", string.Format("{0}/{1}", item.ID, item.urlName));
yield return dynamicNode;
}
}
我的 Mvc.Sitemap 描述是这样的:
<mvcSiteMapNode title="Articles" controller="Articles" action="Show"
dynamicNodeProvider="ArticlesKB.ArticlesNodeProvider, ArticlesKB"/>
到目前为止,这一切都很好。我现在需要弄清楚,我如何在每篇文章中实际添加 <image:image> 节点。
目前在 MvcSiteMapProvider 4 中是否支持?如果是,我需要做什么来实现它?
谢谢!
【问题讨论】:
标签: c# asp.net-mvc seo mvcsitemapprovider