Serve /robots.txt
Some checks failed
Dotnet build and test / log-the-inputs (push) Successful in 4s
Dotnet build and test / build (push) Failing after 1m21s

This commit is contained in:
Paul Schneider
2025-07-10 18:32:58 +01:00
parent 984b76b170
commit 84366812f9
2 changed files with 13 additions and 2 deletions

View File

@ -314,7 +314,17 @@ public static class HostingExtensions
await db.Database.MigrateAsync();
}
}
app.Use(async (context, next) => {
if (context.Request.Path.StartsWithSegments("/robots.txt")) {
var robotsTxtPath = System.IO.Path.Combine(app.Environment.WebRootPath, $"robots.txt");
string output = "User-agent: * \nDisallow: /";
if (File.Exists(robotsTxtPath)) {
output = await File.ReadAllTextAsync(robotsTxtPath);
}
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync(output);
} else await next();
});
app.UseStaticFiles();
app.UseRouting();
app.UseIdentityServer();

View File

@ -1,5 +1,6 @@
User-agent: *
Disallow: /signin
Disallow: /signin-google
Disallow: /Account/Register
Disallow: /External
Disallow: /Command/Create