0
0

Compare commits

..

No commits in common. "f6f75d364fba97a5160dd1232086a903ca9bbaf2" and "57f7cb28a5288ea280be793776998af94773f7fe" have entirely different histories.

5 changed files with 31 additions and 31 deletions

View File

@ -1,10 +0,0 @@
@page
@{
Layout = null;
this.Response.ContentType = "text/plain";
}
User-agent: *
Disallow: /freedom
Disallow: /account
Disallow: /Account
sitemap: https://mydarlingunderwear.ru/sitemap.xml

View File

@ -1,21 +0,0 @@
@page "/sitemap.xml"
@using Microsoft.AspNetCore.Http
@{
var pages = new List<dynamic>
{
new {Url = "https://mydarlingunderwear.ru/", LastUpdated = DateTime.Today}
};
Layout = null;
Response.ContentType = "text/xml";
await Response.WriteAsync("<?xml version='1.0' encoding='UTF-8' ?>");
}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@foreach (var p in pages)
{
<url>
<loc>@p.Url</loc>
<lastmod>@p.LastUpdated.ToString("yyyy-MM-dd")</lastmod>
</url>
}
</urlset>

View File

@ -2,6 +2,7 @@ using Microsoft.EntityFrameworkCore;
using MyDarling.Models;
using MyDarling.Services;
using Microsoft.AspNetCore.Identity;
using MyDarling.Controllers;
var builder = WebApplication.CreateBuilder(args);
@ -27,6 +28,7 @@ builder.Services.Configure<IdentityOptions>( opts =>
});
builder.Services.AddTransient<IImageResizer, ImageResizer>();
builder.Services.AddScoped<IRobotsTxtGenerator, RobotsTxtGenerator>();
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
@ -37,6 +39,10 @@ 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);

17
RobotsTxtGenerator.cs Normal file
View File

@ -0,0 +1,17 @@
using System.Text;
namespace MyDarling.Controllers;
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();
}
}

View File

@ -0,0 +1,8 @@
using System.Text;
namespace MyDarling.Controllers;
public interface IRobotsTxtGenerator
{
public string GetRobotsText();
}