This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Build the project (uses modern .slnx format)
dotnet build BlazorServerBasicAuthSession.slnx
# Run the application
dotnet run --project BlazorServerBasicAuthSession.csproj
# Run in watch mode (hot reload)
dotnet watch --project BlazorServerBasicAuthSession.csprojBlazor Server application (.NET 10 LTS, C# 14) demonstrating session-based authentication without Identity or JWT. Uses ASP.NET Core server sessions with distributed memory cache.
Demo credentials: admin@example.com / 123456 (hardcoded, not for production)
Namespace: BlazorAuth
Modern .NET project structure with centralized configuration:
BlazorServerBasicAuthSession.slnx- Modern XML solution formatBlazorServerBasicAuthSession.csproj- Project file using$(NetVersion)Directory.Build.props- Centralized build propertiesDirectory.Packages.props- Central package version managementglobal.json- SDK version pinning (10.0.103)NuGet.Config- Package source configuration
- Primary constructors for all services
- Sealed classes for services and models
- CancellationToken in all async service methods
- Expression-bodied members for simple methods
- Centralized target framework via
$(NetVersion)property
- Login.razor & Logout.razor - Static SSR (no
@rendermode) - Allows session modification - Home.razor, Counter.razor -
@rendermode InteractiveServer - App.razor - Routes without global rendermode, HeadOutlet with InteractiveServer
Important: Session state cannot be modified over SignalR (InteractiveServer). Auth pages must use Static SSR.
SessionServicemanages HTTP session state viaIHttpContextAccessorAuthenticationServicehandles login/logout, delegates session operations toSessionService- Custom
AuthorizeViewcomponent wraps protected content and redirects unauthenticated users - Logout uses
<a href="/logout">(not@onclick) to trigger HTTP navigation
Services must be registered in this order due to dependencies:
IHttpContextAccessorISessionService(depends on IHttpContextAccessor)IAuthenticationService(depends on ISessionService)
Components/Pages/Shared/AuthorizeView.razor- Custom authorization wrapperComponents/Pages/Login.razor- Static SSR, form with[SupplyParameterFromForm]Components/Pages/Logout.razor- Static SSR, clears session and redirectsComponents/Layout/MainLayout.razor- Logout link (not button)
- 30-minute idle timeout
- HttpOnly cookies
- Essential cookies enabled
- SecurePolicy: Always