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" });