【问题标题】:Implementing Sitecore Multisite Robots.txt files实施 Sitecore Multisite Robots.txt 文件
【发布时间】:2013-10-31 13:34:07
【问题描述】:

如何为托管在同一个 Sitecore 解决方案上的每个网站设置不同的 robots.txt 文件。我想从站点核心项目中读取动态 robots.txt。

【问题讨论】:

    标签: sitecore sitecore6


    【解决方案1】:

    您需要按照以下步骤操作:

    1) 创建并实现您的自定义通用 (.ashx) 处理程序。

    2) 在 web.config 文件中将以下行添加到该部分

    3) 导航到该部分并在此处添加

    4)在主页项目上,您将有“机器人”字段(备忘录或多行字段,而不是 RichText 字段) 您的自定义通用处理程序将如下所示:

     public class Robots : IHttpHandler
    {
    
        public virtual void ProcessRequest(HttpContext context)
        {
            private string defaultRobots = "your default robots.txt content ";
    
            string robotsTxt = defaultRobots;
    
            if ((Sitecore.Context.Site == null) || (Sitecore.Context.Database == null))
            {
                robotsTxt = defaultRobots;
            }
            Item itmHomeNode = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.StartPath);
            if (itmHomeNode != null)
            {
                if ((itmHomeNode.Fields["Robots"] != null) && (itmHomeNode.Fields["Robots"].Value != ""))
                {
                    robotsTxt = itmHomeNode.Fields["Robots"].Value;
                }
            }
    
            context.Response.ContentType = "text/plain";
            context.Response.Write(robotsTxt);
    
        }
    

    【讨论】:

      【解决方案2】:

      我们有类似的问题,尤其是在多站点环境中,所以我们使用处理程序来实现 robots.txt

      创建一个继承自 IHTTPHandler 的新类,并在 process 方法中实现逻辑。将 XML 输出写入上下文对象。

      context.Response.ContentType = "text/plain";
      context.Response.Output.Write({XML DATA});
      

      添加自定义处理程序和触发器。

        <handler trigger="~/Handlers/" handler="robots.txt"/>
      
        <add name="{Name}" path="robots.txt" verb="*" type="{Assembly Name and Type}" />
      

      【讨论】:

        【解决方案3】:

        看来,如果您想访问 Sitecore Context 和任何项目,您需要等到这些问题得到解决。 aboce 方法将始终在 Site 定义中为您提供 null,因为当文件处理程序启动时,这不会解决。

        似乎要获取 Sitecore.Context,您应该在 Sitecore 中实现一个 HttpRequestProcessor,它呈现 robots.txt,本网站上的示例: http://darjimaulik.wordpress.com/2013/03/06/how-to-create-handler-in-sitecore/

        【讨论】:

          【解决方案4】:

          您可以参考这篇博文,详细了解如何使用自定义 HttpRequestProcessor 和自定义机器人设置模板进行操作:http://nsgocev.wordpress.com/2014/07/30/handling-sitecore-multi-site-instance-robots-txt/

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-03-13
            • 1970-01-01
            相关资源
            最近更新 更多