PlotDirector/PlotLine/Services/PublicIndexing.cs

21 lines
770 B
C#

namespace PlotLine.Services;
// Environment protection is independent of catalogue publication/index eligibility.
public static class PublicIndexing
{
public static string Robots(string environment, string requested) =>
string.Equals(environment, Environments.Development, StringComparison.OrdinalIgnoreCase)
? "noindex, follow" : requested;
public static IApplicationBuilder UseDevelopmentNoIndex(this IApplicationBuilder app)
{
if (app.ApplicationServices.GetRequiredService<IWebHostEnvironment>().IsDevelopment())
app.Use(async (context, next) =>
{
context.Response.Headers["X-Robots-Tag"] = "noindex, follow";
await next();
});
return app;
}
}