MvcSiteMapProvider MVC5 CANONICALURL
我想不出有什么不对MVC.SiteMap,当我检查网页的源文件不显示CANONICALURL。
在_layout文件我有以下几点:
I can't figure out what is wrong with MVC.SiteMap, it does not display CanonicalUrl when I check the page source. In _layout file I have the following:
@Html.MvcSiteMap().CanonicalTag()
@Html.MvcSiteMap().MetaRobotsTag()
下面是MVC.Sitemap:
Here is MVC.Sitemap:
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">
<mvcSiteMapNode title="Home" controller="Home" action="Index" metaRobotsValues="noindex" CanonicalUrl="/Home/Index">
<mvcSiteMapNode title="Healthcare Services" controller="Home" action="Healthcare" metaRobotsValues="noindex follow" CanonicalUrl="/Home/Healthcare"/>
<mvcSiteMapNode title="About" controller="Home" action="About" metaRobotsValues="noindex" CanonicalUrl="/Home/About"/>
<mvcSiteMapNode title="Training" controller="Home" action="Training" metaRobotsValues="noindex follow" canonicalUrl="/Home/Training"/>
<mvcSiteMapNode title="Environmental Services" controller="Home" action="Environment" metaRobotsValues="follow" canonicalUrl="/Home/Environment"/>
<mvcSiteMapNode title="IT Services" controller="Home" action="Internet" metaRobotsValues="noindex" CanonicalUrl="/Home/Internet"/>
<mvcSiteMapNode title="Our Clients" controller="Home" action="Clients" metaRobotsValues="noindex noarchive" canonicalUrl="/Home/Clients"/>
<mvcSiteMapNode title="Privacy" controller="Home" action="Privacy" metaRobotsValues="noindex noarchive" canonicalUrl="/Home/Privacy"/>
</mvcSiteMapNode>
</mvcSiteMap>
请问AP preciate您的建议。
Would appreciate your suggestions.
的规范标签是用来表示2 URL指向相同的资源(通常具有相同或非常相似的内容另一页)。
The canonical tag is used to indicate that 2 URLs point to the same resource (usually another page with the same or very similar content).
在您的配置,配置的每个节点都有自己的控制器和动作,没有迹象表明存在与相同内容的另一个节点。由于每个节点是它自己的规范URL标签将不会显示。它仅显示在具有匹配CANONICALURL或canonicalKey备用页面。例如,如果你的 /主页/培训
和 /主页/环境
动作都显示相同的内容,你想指定 /主页/培训
是原始和 /主页/环境
被复制,您可以配置这样的节点
In your configuration, you are configuring each node with its own controller and action, with no indication that there is another node with identical content. Since each node is its own canonical URL the tag will not be shown. It is only displayed on alternate pages with a matching canonicalUrl or canonicalKey. For example, if your /Home/Training
and /Home/Environment
actions both serve the same content and you want to specify that /Home/Training
is the original and /Home/Environment
is the copy, you configure the nodes like this:
<mvcSiteMapNode title="Training" controller="Home" action="Training" metaRobotsValues="noindex follow"/>
<mvcSiteMapNode title="Environmental Services" controller="Home" action="Environment" metaRobotsValues="follow" canonicalUrl="/Home/Training"/>
您还会看到只生成了 /主页/环境
页的 /主页/培训页
You will then see the canonical tag generated only for the /Home/Environment
page with an absolute URL of the /Home/Training
page.
然而,一个更易于维护的选择是使用canonicalKey而不是CANONICALURL。这样一来,如果 /主页/培训网址更改
您不必更新它为每个指定它为规范节点的节点。
However, a more maintainable option is to use canonicalKey instead of canonicalUrl. That way, if the URL changes on /Home/Training
you don't have to update it for every node that specifies it as the canonical node.
<mvcSiteMapNode title="Training" controller="Home" action="Training" metaRobotsValues="noindex follow" key="Home_Training"/>
<mvcSiteMapNode title="Environmental Services" controller="Home" action="Environment" metaRobotsValues="follow" canonicalKey="Home_Training"/>
CANONICALURL有没有的情况下,您指定不受MVC托管或外部的网站规范网页。
CanonicalUrl is there in case you are specifying canonical pages that are not hosted by MVC or are external to the website.