如何为同一 Sitecore 解决方案上托管的每个网站实现不同的 robots.txt 文件。我想从 sitecore 项目中动态读取 robots.txt。
您需要执行以下步骤:
1) 创建并实现您的自定义通用 (.ashx) 处理程序。
2) 在 web.config 文件中将以下行添加到该部分
3) 导航到该部分并在此处添加
4)在主页项目上,您将有“机器人”字段(备忘录或多行字段,而不是富文本字段)
您的自定义通用处理程序将如下所示:
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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)