次のようにあなたのrobots.txtを処理するカスタムハンドラを追加することができます。そして、あなたのashx
の背後にあるコードでは、あなたがするために必要なロジックを記述することができます
<customHandlers>
<handler trigger="robots.txt" handler="RobotsTxtHandler.ashx" />
</customHandlers>
を必要なrobots.txtを読み込みます。
public void ProcessRequest(HttpContext context)
{
var database = Factory.GetDatabase("web");
var path = string.Format("{0}{1}", Context.Site.RootPath, Context.Site.StartItem)
Item siteRoot = database.GetItem(path)
if (siteRoot != null)
{
context.Response.Clear();
context.Response.ContentType = "text/plain";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
//Write your code to fetch the robots.txt from sitecore item
}
context.Response.End();
}
ASHXの分離コードは、あなたが<system.webServer> <handlers>
タグの下にweb.configファイルにハンドラを追加することも必要IHTTPハンドラに
を継承する必要があることに注意してください。
<add verb="*" path="RobotsTxtHandler.ashx" type="YourNamespace.RobotsTxtHandler, YourAssembly" name="RobotsTxtHandler" />
私の提案は、あなたの代わりにWebサイトのルートディレクトリのサイトコアの項目で各サイトのrobots.txtのを保存することが望ましいだろうということです。これにより、各サイトは独自のロボットを持つことができます。