将X-Robot-Tag添加到Sitecore 8中的响应头

Aru*_*mar 1 c# sitemap asp.net-mvc sitecore sitecore8

我在Sitecore有一个网站设置.我的站点地图是sitecore中的一个项目,位于主页下方.

我可以通过输入以下URL来访问我的站点地图:http: //example.com/xmlsitemap 而xmlsitemap是Sitecore中项目的名称.其中有渲染来获取下面给出的XML站点地图:

XmlDocument SiteMap = new XmlDocument();
SiteMap.Load(System.Web.HttpContext.Current.Server.MapPath("~/") + "//SiteMap//Sitemap-" + Sitecore.Context.Site.SiteInfo.Name + ".xml");
return this.Content(SiteMap.InnerXml, "text/xml");
Run Code Online (Sandbox Code Playgroud)

我在sitecore中有多个站点设置.这就是我将sitemap创建为sitecore中的Item的原因.这样它就可以为每个网站获得正确的站点地图.

问题是当我使用URL将此站点地图提交给谷歌时.它也会对站点地图网址建立索引,并且它会显示在实际结果中.

我知道我可以通过添加X-Robot-Tag:noindex来阻止谷歌索引我的站点地图.但我不能这样做,因为它不是网站目录中的项目.

关于如何实现这一点的任何想法?

jam*_*kam 10

您可以web.config通过在位置节点中指定标头来指定标头.

<configuration>
...
    <location path="xmlsitemap">
        <system.webServer>
            <httpProtocol>
                <customHeaders>
                    <add name="X-Robots-Tag" value="noindex" />
                </customHeaders>
            </httpProtocol>
        </system.webServer>
    </location>
</configuration>
Run Code Online (Sandbox Code Playgroud)

您可以手动添加此文件,该文件不需要实际存在于IIS中.