From 1a9afa278f6c9cb603cb017b76714ee502223de4 Mon Sep 17 00:00:00 2001 From: Levi Zitting Date: Sun, 9 Aug 2026 18:26:02 -0500 Subject: [PATCH] feat: control search indexing at runtime --- src/MethodConf.Cms/Program.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/MethodConf.Cms/Program.cs b/src/MethodConf.Cms/Program.cs index 29b94bc..aed9c9d 100644 --- a/src/MethodConf.Cms/Program.cs +++ b/src/MethodConf.Cms/Program.cs @@ -5,6 +5,8 @@ using Serilog; var builder = WebApplication.CreateBuilder(args); +var searchIndexingEnabled = builder.Configuration.GetValue( + "MethodConf:Site:SearchIndexingEnabled", true); builder.CreateUmbracoBuilder() .AddBackOffice(mvc => @@ -36,6 +38,21 @@ await app.BootUmbracoAsync(); +if (!searchIndexingEnabled) +{ + app.Use(async (context, next) => + { + context.Response.Headers["X-Robots-Tag"] = "noindex, nofollow"; + await next(); + }); +} + +app.MapGet("/robots.txt", () => Results.Text( + searchIndexingEnabled + ? "User-agent: *\nAllow: /\n" + : "User-agent: *\nDisallow: /\n", + "text/plain")).AllowAnonymous(); + app.MapControllerRoute("default", "/", new { Controller = "Home", Action = "Index" });