Move robots.txt to Razor Pages
This commit is contained in:
parent
3655495dfd
commit
ecf537fdca
9
Pages/Robots.txt.cshtml
Normal file
9
Pages/Robots.txt.cshtml
Normal file
@ -0,0 +1,9 @@
|
||||
@page
|
||||
@{
|
||||
Layout = null;
|
||||
this.Response.ContentType = "text/plain";
|
||||
}
|
||||
User-agent: *
|
||||
Disallow: /freedom
|
||||
Disallow: /account
|
||||
Disallow: /Account
|
@ -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<IdentityOptions>( opts =>
|
||||
});
|
||||
|
||||
builder.Services.AddTransient<IImageResizer, ImageResizer>();
|
||||
builder.Services.AddScoped<IRobotsTxtGenerator, RobotsTxtGenerator>();
|
||||
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<IRobotsTxtGenerator>();
|
||||
app.MapGet("/robots.txt", () => robotsGenerator!.GetRobotsText());
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
IdentitySeedData.CreateAdminAccount(app.Services, app.Configuration);
|
||||
|
@ -1,6 +0,0 @@
|
||||
namespace MyDarling.Services;
|
||||
|
||||
public interface IRobotsTxtGenerator
|
||||
{
|
||||
public string GetRobotsText();
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user