101 lines
3.3 KiB
C#
101 lines
3.3 KiB
C#
using System.IO.Compression;
|
|
|
|
using CatherineLynwood.Middleware;
|
|
using CatherineLynwood.Services;
|
|
|
|
using Microsoft.AspNetCore.ResponseCompression;
|
|
|
|
using WebMarkupMin.AspNetCoreLatest;
|
|
|
|
namespace CatherineLynwood
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Retrieve the connection string from appsettings.json
|
|
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
|
|
|
builder.Services.AddSingleton(new DataAccess(connectionString));
|
|
|
|
builder.Services.AddControllersWithViews();
|
|
|
|
// Add IHttpContextAccessor for accessing HTTP context in tag helpers
|
|
builder.Services.AddHttpContextAccessor();
|
|
|
|
builder.Services.AddHttpClient();
|
|
|
|
// ✅ Add session services (in-memory only)
|
|
builder.Services.AddSession(options =>
|
|
{
|
|
options.IdleTimeout = TimeSpan.FromMinutes(30);
|
|
options.Cookie.HttpOnly = true;
|
|
options.Cookie.IsEssential = true;
|
|
});
|
|
|
|
// ✅ Register the book access code service
|
|
builder.Services.AddScoped<IAccessCodeService, AccessCodeService>();
|
|
|
|
// Add response compression services
|
|
builder.Services.AddResponseCompression(options =>
|
|
{
|
|
options.EnableForHttps = true;
|
|
options.Providers.Add<BrotliCompressionProvider>();
|
|
options.Providers.Add<GzipCompressionProvider>();
|
|
});
|
|
|
|
builder.Services.Configure<BrotliCompressionProviderOptions>(options =>
|
|
{
|
|
options.Level = CompressionLevel.Fastest;
|
|
});
|
|
|
|
builder.Services.Configure<GzipCompressionProviderOptions>(options =>
|
|
{
|
|
options.Level = CompressionLevel.Fastest;
|
|
});
|
|
|
|
// Add HTML minification
|
|
builder.Services.AddWebMarkupMin(options =>
|
|
{
|
|
options.AllowMinificationInDevelopmentEnvironment = true;
|
|
})
|
|
.AddHtmlMinification()
|
|
.AddHttpCompression()
|
|
.AddXmlMinification()
|
|
.AddXhtmlMinification();
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Home/Error");
|
|
app.UseHsts(); // Adds the HSTS (HTTP Strict Transport Security) header
|
|
}
|
|
|
|
app.UseMiddleware<BlockPhpRequestsMiddleware>();
|
|
app.UseMiddleware<RedirectToWwwMiddleware>();
|
|
app.UseMiddleware<RefererValidationMiddleware>();
|
|
app.UseMiddleware<HoneypotLoggingMiddleware>();
|
|
app.UseMiddleware<IpqsBlockMiddleware>();
|
|
|
|
app.UseHttpsRedirection();
|
|
app.UseResponseCompression();
|
|
app.UseStaticFiles();
|
|
app.UseWebMarkupMin();
|
|
app.UseRouting();
|
|
app.UseSession();
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllerRoute(
|
|
name: "default",
|
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
|
|
|
app.Run();
|
|
}
|
|
}
|
|
}
|