🚀 Bereit für Ihre digitale Transformation?
Vereinbaren Sie ein unverbindliches Strategiegespräch
📊 Business Value
ASP.NET Core ist Microsofts High-Performance-Webframework für moderne Unternehmensanwendungen. Diese App demonstriert die Standard-Architektur mit Razor Pages, Dependency Injection und Production-Security-Features.
builder.Services.AddRazorPages() – testbar und wartbar.⚙️ Architektur
WebApplication Builder
WebApplication.CreateBuilder(args) initialisiert den DI-Container und registriert AddRazorPages() als Service.
Middleware Pipeline
UseHttpsRedirection → UseStaticFiles → UseRouting → UseAuthorization → MapRazorPages.
Razor Pages
PageModel-Klassen (Index, Error, Privacy) mit ILogger<T>-Injection via Constructor-DI.
Production Security
HSTS mit 30-Tage-Default, Exception-Handling nur in Development – keine Leaks in Produktion.
💻 Echter Code aus dem Projekt
Direkt aus D:\arbeit\git\WebApplication1\ — C#-Code aus Visual Studio.
🏗️ Program.cs: ASP.NET Core Startup & Middleware-Pipeline
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
📄 Index.cshtml.cs: Razor Page Model mit Dependency Injection
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApplication1.Pages;
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public void OnGet()
{
// Wird bei jedem GET-Request auf / ausgeführt
}
}
⚠️ Error.cshtml.cs: Zentrale Fehlerbehandlung
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;
namespace WebApplication1.Pages;
[ResponseCache(
Duration = 0, Location = ResponseCacheLocation.None,
NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }
public bool ShowRequestId =>
!string.IsNullOrEmpty(RequestId);
private readonly ILogger<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public void OnGet()
{
RequestId = Activity.Current?.Id
?? HttpContext.TraceIdentifier;
}
}
🛠️ Technologie-Stack
ILogger<T> wird automatisch via Constructor-Injection bereitgestellt.ILogger-Interface – integriert mit ASP.NET Core Logging-Providern.🚀 In Tagen zum MVP — nicht in Monaten
Bereit für Ihren Wettbewerbsvorteil?
Von .NET Enterprise-Apps bis Python-Automation — ich entwickle, was Ihr Business braucht.