How ASP.NET Core Samples Are Structured in the dotnet/aspnetcore Repository

ASP.NET Core samples are organized under src/<Component>/samples/ as self-contained projects, each containing a project file, entry point, and configuration files that can be executed independently with dotnet run.

The dotnet/aspnetcore repository houses hundreds of runnable sample applications that demonstrate specific framework features. These samples follow a strict organizational hierarchy that maps directly to ASP.NET Core component areas, enabling developers to quickly locate working implementations of SignalR, Middleware, Identity, and other capabilities.

Directory Structure and Organization

All samples reside within the src/ folder and follow a consistent three-level hierarchy:


src/
 └─ <Component>/
     └─ samples/
         └─ <SampleName>/
             ├─ *.csproj / *.fsproj
             ├─ Program.cs | Program.fs
             ├─ Startup.cs (optional)
             ├─ appsettings*.json
             ├─ launchSettings.json
             └─ wwwroot/ (if applicable)

  • <Component> represents the ASP.NET Core area being demonstrated, such as SignalR, Middleware/WebSockets, Identity, Http, or Antiforgery.
  • <SampleName> is a self-contained directory containing all files necessary to build and execute the project.
  • Each sample is fully isolated, meaning you can navigate to any sample folder and execute dotnet run without additional dependencies.

Most components organize samples under src/<Component>/samples/<SampleName>/, though some simpler components like Middleware/Session place sample files directly under src/Middleware/Session/samples/ without an additional subdirectory.

Sample Project Components

Project Files and Entry Points

Every sample includes a project file (*.csproj for C# or *.fsproj for F#) that defines the target framework and package references. The entry point is typically Program.cs (or Program.fs), which configures the minimal hosting model:

// Example from src/SignalR/samples/WebSocketSample/Program.cs
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Middleware configuration
app.Run();

Legacy samples may include a separate Startup.cs file containing the ConfigureServices and Configure methods, as seen in src/SignalR/samples/SocialWeather/Startup.cs.

Configuration and Static Assets

Samples include appsettings.json for default configuration settings such as logging levels and Kestrel endpoints. Debug-specific settings reside in launchSettings.json. Samples serving web content include a wwwroot/ folder containing static HTML, CSS, and JavaScript files, such as src/Middleware/WebSockets/samples/EchoApp/wwwroot/index.html.

How to Run the Samples

Each sample is designed to execute independently. Navigate to the specific sample directory and use the .NET CLI:


# Example: Running the SignalR WebSocketSample

cd src/SignalR/samples/WebSocketSample
dotnet run

# Example: Running the Middleware StaticFileSample

cd src/Middleware/StaticFiles/samples/StaticFileSample
dotnet run

The project file automatically references the necessary ASP.NET Core libraries from the repository, eliminating the need for manual package restoration in most cases.

Real-World Examples by Component

The repository contains diverse samples demonstrating specific framework capabilities:

Summary

  • ASP.NET Core samples follow the src/<Component>/samples/<SampleName>/ hierarchy.
  • Each sample is a self-contained project with its own .csproj, entry point, and configuration files.
  • Entry points are typically Program.cs (minimal hosting) or Startup.cs (legacy configuration).
  • Samples can be executed immediately using dotnet run from their respective directories.
  • Static assets are isolated within wwwroot/ folders inside individual sample directories.

Frequently Asked Questions

Where are ASP.NET Core samples located in the repository?

Samples are located under the src/ directory, organized by component area. The full path pattern is src/<Component>/samples/<SampleName>/, such as src/SignalR/samples/WebSocketSample/ or src/Identity/samples/IdentitySample.PasskeyUI/.

Can I run ASP.NET Core samples directly from the repository?

Yes. Each sample is a standalone project that builds against the repository's source code. Navigate to any sample folder (for example, src/Http/samples/MinimalSample/) and execute dotnet run to launch the application without additional setup.

What is the difference between Program.cs and Startup.cs in the samples?

Program.cs is the modern entry point used in minimal hosting models, containing WebApplication.CreateBuilder() and middleware configuration. Startup.cs appears in older samples and separates service configuration (ConfigureServices) from the request pipeline (Configure), as seen in src/SignalR/samples/SocialWeather/Startup.cs.

Are there F# samples available in the repository?

Yes. While C# dominates, the repository structure supports F# samples using *.fsproj project files and Program.fs entry points. The organizational structure remains identical regardless of language.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →