From ecf537fdca168b2acf3b0ee6fae1f5a2c78aafee Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Thu, 15 Jun 2023 07:32:35 +0300 Subject: [PATCH] Move robots.txt to Razor Pages --- Pages/Robots.txt.cshtml | 9 +++++++++ Program.cs | 6 ------ Services/IRobotsTxtGenerator.cs | 6 ------ Services/RobotsTxtGenerator.cs | 17 ----------------- 4 files changed, 9 insertions(+), 29 deletions(-) create mode 100644 Pages/Robots.txt.cshtml delete mode 100644 Services/IRobotsTxtGenerator.cs delete mode 100644 Services/RobotsTxtGenerator.cs diff --git a/Pages/Robots.txt.cshtml b/Pages/Robots.txt.cshtml new file mode 100644 index 0000000..54c25f2 --- /dev/null +++ b/Pages/Robots.txt.cshtml @@ -0,0 +1,9 @@ +@page +@{ + Layout = null; + this.Response.ContentType = "text/plain"; +} +User-agent: * +Disallow: /freedom +Disallow: /account +Disallow: /Account \ No newline at end of file diff --git a/Program.cs b/Program.cs index 60f5c15..3dbb243 100644 --- a/Program.cs +++ b/Program.cs @@ -2,7 +2,6 @@ using Microsoft.EntityFrameworkCore; using MyDarling.Models; using MyDarling.Services; using Microsoft.AspNetCore.Identity; -using MyDarling.Controllers; var builder = WebApplication.CreateBuilder(args); @@ -28,7 +27,6 @@ builder.Services.Configure( opts => }); builder.Services.AddTransient(); -builder.Services.AddScoped(); builder.Services.AddControllersWithViews(); builder.Services.AddRazorPages(); @@ -39,10 +37,6 @@ app.MapControllers(); app.MapDefaultControllerRoute(); app.MapRazorPages(); -var robotsScope = app.Services.CreateScope(); -var robotsGenerator = robotsScope.ServiceProvider.GetService(); -app.MapGet("/robots.txt", () => robotsGenerator!.GetRobotsText()); - app.UseAuthentication(); app.UseAuthorization(); IdentitySeedData.CreateAdminAccount(app.Services, app.Configuration); diff --git a/Services/IRobotsTxtGenerator.cs b/Services/IRobotsTxtGenerator.cs deleted file mode 100644 index 6f49924..0000000 --- a/Services/IRobotsTxtGenerator.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace MyDarling.Services; - -public interface IRobotsTxtGenerator -{ - public string GetRobotsText(); -} diff --git a/Services/RobotsTxtGenerator.cs b/Services/RobotsTxtGenerator.cs deleted file mode 100644 index 26e5cee..0000000 --- a/Services/RobotsTxtGenerator.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Text; - -namespace MyDarling.Services; - -public class RobotsTxtGenerator : IRobotsTxtGenerator -{ - public string GetRobotsText() - { - StringBuilder stringBuilder = new(); - stringBuilder.AppendLine("user-agent: *"); - stringBuilder.AppendLine("Disallow: /freedom"); - stringBuilder.AppendLine("Disallow: /Account/"); - stringBuilder.AppendLine("Disallow: /account/"); - - return stringBuilder.ToString(); - } -}