๐ 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.