本文介绍了实现Sitecore多站点robots.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何实现为同一Sitecore解决方案上托管的每个网站提供不同的robots.txt文件。我想阅读Sitecore Items中的动态robots.txt。推荐答案
您需要执行以下步骤:
1)创建并实现您的自定义通用(.ashx)处理程序。2)在web.config文件中,将以下行添加到部分
3)导航到部分并在此处添加
4)在主页项目上,您将有"Robots"字段(备注或多行字段,而不是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);
}
这篇关于实现Sitecore多站点robots.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!