web: založení projektu Helpdesk.Web a layout aplikace
ASP.NET Core MVC (.NET 10) s Bootstrapem 5, layout s menu podle role, chybové stránky, bezpečnostní hlavičky (CSP, Referrer-Policy) a česká kultura. Refs #19, #20
This commit is contained in:
1 parent
b402d9f92c
commit
abd075287c
25 files changed
+523
No files matched your search
@@ -0,0 +1,70 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using Helpdesk.Web.Infrastructure;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Services.AddControllersWithViews(options =>
|
||||
{
|
||||
// Anti-forgery token u všech formulářů odesílaných metodou POST (CSRF, kap. 10).
|
||||
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
|
||||
});
|
||||
|
||||
// Klíče Data Protection šifrují autentizační cookie. Bez uložení na volume by
|
||||
// restart kontejneru odhlásil všechny uživatele (kap. 15.3).
|
||||
var dataProtection = builder.Services.AddDataProtection().SetApplicationName("Helpdesk.Web");
|
||||
var keysPath = builder.Configuration["DataProtection:KeysPath"];
|
||||
if (!string.IsNullOrWhiteSpace(keysPath))
|
||||
dataProtection.PersistKeysToFileSystem(new DirectoryInfo(keysPath));
|
||||
|
||||
var trustedProxy = builder.Configuration["ReverseProxy:TrustedIp"];
|
||||
if (!string.IsNullOrWhiteSpace(trustedProxy))
|
||||
{
|
||||
if (!IPAddress.TryParse(trustedProxy, out var proxyAddress))
|
||||
throw new InvalidOperationException("Nastavte platnou IP adresu důvěryhodné reverse proxy.");
|
||||
|
||||
builder.Services.Configure<ForwardedHeadersOptions>(options =>
|
||||
{
|
||||
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
||||
options.KnownIPNetworks.Clear();
|
||||
options.KnownProxies.Clear();
|
||||
options.KnownProxies.Add(proxyAddress);
|
||||
});
|
||||
}
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(trustedProxy))
|
||||
app.UseForwardedHeaders();
|
||||
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/error");
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseStatusCodePagesWithReExecute("/error/{0}");
|
||||
app.UseSecurityHeaders();
|
||||
|
||||
var czech = new CultureInfo("cs-CZ");
|
||||
app.UseRequestLocalization(new RequestLocalizationOptions
|
||||
{
|
||||
DefaultRequestCulture = new RequestCulture(czech),
|
||||
SupportedCultures = [czech],
|
||||
SupportedUICultures = [czech],
|
||||
});
|
||||
|
||||
app.UseRouting();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapStaticAssets();
|
||||
app.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}").WithStaticAssets();
|
||||
|
||||
app.Run();
|
||||
|
||||
/// <summary>Vstupní bod – veřejný kvůli testům (WebApplicationFactory).</summary>
|
||||
public partial class Program;
|
||||
Reference in new issue
Block a user