๐ŸŒ WebApplication1 โ€” ASP.NET Core Razor Pages App

Moderne .NET-Webanwendung mit ASP.NET Core 8.0, Razor Pages und Dependency Injection โ€“ C#-basiertes Webprojekt

ASP.NET Core 8.0C#Razor PagesDependency Injection

๐Ÿš€ Bereit fรผr Ihre digitale Transformation?

Vereinbaren Sie ein unverbindliches Strategiegesprรคch

๐Ÿ“ž 02406 803 7603 โœ‰๏ธ info@computerkumpel.de

๐Ÿ“Š 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.

๐Ÿš€
Performance
ASP.NET Core ist eines der schnellsten Webframeworks โ€“ optimiert fรผr hohe Requests-per-Second bei minimaler Latenz.
๐Ÿ”’
Security-by-Default
HSTS, HTTPS-Redirection und Authorization-Middleware sind ab Werk konfiguriert โ€“ production-ready ab Tag 1.
๐Ÿ—๏ธ
DI-Architektur
Built-in Dependency Injection mit builder.Services.AddRazorPages() โ€“ testbar und wartbar.
๐Ÿ”„
Cross-Platform
Lรคuft auf Windows, Linux und macOS โ€“ Deployment-Flexibilitรคt ohne Code-ร„nderungen.

โš™๏ธ Architektur

1
๐Ÿ—๏ธ

WebApplication Builder

WebApplication.CreateBuilder(args) initialisiert den DI-Container und registriert AddRazorPages() als Service.

โ†’
2
๐Ÿ”—

Middleware Pipeline

UseHttpsRedirection โ†’ UseStaticFiles โ†’ UseRouting โ†’ UseAuthorization โ†’ MapRazorPages.

โ†’
3
๐Ÿ“„

Razor Pages

PageModel-Klassen (Index, Error, Privacy) mit ILogger<T>-Injection via Constructor-DI.

โ†’
4
๐Ÿ›ก๏ธ

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

๐Ÿ’œ
C# 12 / .NET 8.0
Moderne C#-Features: Top-Level Statements, Nullable-Reference-Types, File-Scoped-Namespaces.
๐ŸŒ
ASP.NET Core
Microsofts Cross-Platform-Webframework mit Middleware-Pipeline, Routing, Authorization.
๐Ÿ“„
Razor Pages
Page-Centric MVC mit Code-Behind: .cshtml (View) + .cshtml.cs (PageModel).
๐Ÿ’‰
Dependency Injection
Built-in DI-Container. ILogger<T> wird automatisch via Constructor-Injection bereitgestellt.
๐Ÿ”
HSTS & HTTPS
HTTP Strict Transport Security mit 30-Tage-Default, automatische HTTPS-Redirection.
๐Ÿ”
Logging
Strukturiertes Logging via ILogger-Interface โ€“ integriert mit ASP.NET Core Logging-Providern.

๐Ÿš€ In Tagen zum MVP โ€” nicht in Monaten

๐Ÿ“ž 02406 803 7603 โœ‰๏ธ info@computerkumpel.de

Bereit fรผr Ihren Wettbewerbsvorteil?

Von .NET Enterprise-Apps bis Python-Automation โ€” ich entwickle, was Ihr Business braucht.

๐Ÿ“ž Jetzt anrufen โœ‰๏ธ E-Mail senden