MvcSiteMapProvider MVC5 CANONICALURL [英] MvcSiteMapProvider MVC5 CanonicalUrl

查看:136
本文介绍了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"/>

您还会看到只生成了 /主页/环境页的 /主页/培训<绝对URL /的规范标签code>页

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.

这篇关于MvcSiteMapProvider MVC5 CANONICALURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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