ASP.NET Core cheat sheet
A scannable ASP.NET Core reference: 8 short snippets across 6 topics, each linking back to the lesson it came from.
At a glance
| Topic | What it covers | |
|---|---|---|
| Configuration and logging | Configuration is a flat key/value store assembled from several providers. Later providers override earlier ones, so the | lesson |
| Model validation and Problem Details responses | Data annotations, automatic 400 responses and a consistent error shape that a client can parse without guessing | lesson |
| Data access with Entity Framework Core | DbContext lifetime, migrations, loading strategies and the N+1 queries that turn a fast endpoint into a slow one | lesson |
| Razor Pages and MVC views | Page models group a URL's handlers with its markup, and tag helpers remove the stringly-typed parts of a view | lesson |
| Interactive UI with Blazor | Server, WebAssembly and hybrid differ in where the code runs. That single decision drives latency, deployment and what | lesson |
| Real-time features with SignalR | Hubs, groups and reconnection, and the scaling decision that has to be made before the first user connects, not after | lesson |
Quick snippets
Configuration and logging
The configuration stack
{
"Shop": {
"PageSize": 25,
"RetryCount": 3,
"PricingBaseUrl": "https://pricing.internal/"
},
"ConnectionStrings": {
"Default": "Data Source=shop.db"
}
}
The configuration stack
# section separator is a double underscore
Shop__RetryCount=5 dotnet run --project src/Shop.Api
# developer secrets stay outside the repository
dotnet user-secrets init --project src/Shop.Api
dotnet user-secrets set "ConnectionStrings:Default" "Data Source=dev.db" --project src/Shop.Api
Structured logging
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"System.Net.Http.HttpClient": "Warning"
}
}
}Full lesson: Configuration and logging →
Model validation and Problem Details responses
Problem Details, automatically
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"Sku": ["The Sku field is required."],
"Qty": ["The field Qty must be between 1 and 10000."]
},
"traceId": "00-9f2b1c4d5e6f-01"
}Full lesson: Model validation and Problem Details responses →
Data access with Entity Framework Core
Migrations, loading and N+1
# Migrations are code: review them like code
dotnet ef migrations add AddOrderIndex --output-dir Data/Migrations
dotnet ef migrations script --idempotent -o migrate.sql
dotnet ef database update
# See the SQL a query produces, without running the app
dotnet ef dbcontext optimize --output-dir Compiled --namespace App.CompiledFull lesson: Data access with Entity Framework Core →
Razor Pages and MVC views
Page models and handlers
<form method="post">
<!-- The anti-forgery token is added by the form tag helper -->
<input asp-for="Input.Note" class="form-control" />
<span asp-validation-for="Input.Note" class="text-danger"></span>
<button type="submit" asp-page-handler="Save">Save</button>
<a asp-page="/Orders/Index" asp-route-id="@Model.Input.Id">Cancel</a>
</form>
@section Scripts {
<partial name="_ValidationScriptsPartial" />
}Full lesson: Razor Pages and MVC views →
Interactive UI with Blazor
The hosting models
// Program.cs on the server
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();
var app = builder.Build();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode()
.AddInteractiveWebAssemblyRenderMode();Full lesson: Interactive UI with Blazor →
Real-time features with SignalR
Connections, reconnection and scale-out
// Scale out: without a backplane, messages only reach clients on one instance
builder.Services.AddSignalR()
.AddStackExchangeRedis(builder.Configuration.GetConnectionString("Redis"), o =>
{
o.Configuration.ChannelPrefix = RedisChannel.Literal("orders");
});
// Also raise the per-message limit when clients send large payloads
builder.Services.AddSignalR(o => o.MaximumReceiveMessageSize = 64 * 1024);
app.MapHub<OrderHub>("/hubs/orders").RequireAuthorization();Full lesson: Real-time features with SignalR →
FAQ
Is this ASP.NET Core cheat sheet free to use?
Yes. No sign-up and no tracking: the page is static, every example is on the page itself, and you can print it or save it as a one-page reference.
Where do the examples come from?
Every snippet is taken from the 6 lessons of the ASP.NET Core course on this site, and each section links back to the lesson it was pulled from.
How do I go deeper than a cheat sheet?
Open the full ASP.NET Core course — it carries the worked explanations, the edge cases and the exercises behind every line here.
Related cheat sheets
Last refreshed 2026-09-27.