🌐 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