Business & .NET

ASP.NET Core security on day one

The defaults give you a strong starting point; the work is understanding what they do and where they stop.

A studio illustration of layered ASP.NET Core security defaults and middleware order.

Security is defaults, not slogans

The ASP.NET Core security documentation describes a broad set of protections, from authentication and authorization to antiforgery, data protection and transport security. That breadth is useful, but it is also a responsibility: a default you do not understand is a default you can accidentally disable. Security is not a feature you bolt on at the end. It is a set of small decisions made consistently from the first commit.

HTTPS and the middleware pipeline

It turns a plain request into a request to the secure endpoint, and it is cheap to add. It is not the same thing as understanding transport security in depth: certificates still have to be managed, HSTS needs thought, and a proxy in front of the application changes which headers you trust. The middleware pipeline itself is a security concept, because order matters. A component that runs before authentication sees unauthenticated requests; a component that runs after it can rely on a known identity. A well-ordered pipeline makes the rest of the security story easier to reason about. A careless one can leak information or skip a check without any obvious error message.

Authentication and authorization

Authentication answers who the caller is; authorization answers what that caller may do. Keeping those two questions separate is one of the best habits in ASP.NET Core. The Identity documentation covers the built-in membership system, including user storage, password handling and the usual account flows. A rule such as who may approve a record should live in one place, be testable and be applied wherever that action is possible. That is a quiet but powerful habit: it is much easier to list the exceptions than to discover later that a new endpoint forgot a check.

Antiforgery on real forms

Cross-site request forgery is easy to underestimate because the attack uses the user's browser rather than a broken password. The antiforgery documentation explains how ASP.NET Core issues a token with a form and validates it on the next state-changing request. In Razor pages this is usually automatic, but a minimal API or a custom form needs deliberate wiring. It is intentionally small. The point is not to show every option; it is to show that the pieces are ordinary middleware and endpoint metadata, not magic. OWASP Top 10 2025 keeps broken access control high on its list, which is a good reason to treat these checks as routine engineering rather than ceremony.

csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAntiforgery();
builder.Services.AddAuthentication().AddCookie();
builder.Services.AddAuthorization();

var app = builder.Build();

app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseAntiforgery();

app.MapGet("/health", () => Results.Ok("ok"));

app.MapPost("/contact", async (
    HttpContext context,
    ContactRequest request,
    IAntiforgery antiforgery) =>
{
    if (!await antiforgery.IsRequestValidAsync(context))
    {
        return Results.BadRequest();
    }

    return Results.Ok();
}).RequireAuthorization();

app.Run();

public sealed record ContactRequest(string Name, string Email, string Message);

Data protection

ASP.NET Core includes a data protection system that handles keys for things like cookies, tokens and other small pieces of protected state. The point is not that the framework is unbreakable; it is that key management is a discipline, and a shared, tested mechanism beats an improvised one. A local key store that works on a developer machine may behave differently in a container that restarts. Data protection is not only about encryption; it is about knowing which values deserve protection and for how long.

Logging without leaking secrets

Logging is a security control with a strange reputation. Too little and you cannot reconstruct an incident; too much and your logs become a second database of sensitive information. Structured logging helps because fields can be filtered and redacted deliberately. The OWASP Top Ten project is a useful reference here because it keeps the conversation focused on recurring classes of risk rather than on a single tool. Those are usually well-intentioned debugging aids that become a liability the moment the system handles real user data. A quiet, useful log line is better than a loud one that tells an attacker everything.

Headers and boundary layers

Some of the cheapest protections live in response headers and in the configuration of the server in front of the application. Security headers can reduce the impact of browser-based attacks, and CSP in particular requires care because it can break a front end if introduced carelessly. The boundary also includes CORS, rate limiting and the trusted proxy configuration. Each of these answers a different question: which sites may call the API, how much traffic is reasonable, and which forwarded headers we believe. A header or a policy that conflicts with the product's real behaviour will be disabled by someone under pressure, and then you have worse documentation than before.

Where defaults stop being enough

The defaults in ASP.NET Core are a good starting point, not a completed threat model. A public API facing the internet needs different care from an internal tool behind a VPN. A system handling health, financial or personal data needs stricter decisions about storage, logging and retention. Multitenant applications add the question of whether one user can reach another tenant's record, which no framework can infer from a route parameter. That is where patching and review belong in the same conversation as middleware order. Calm honesty about the limits of the defaults is more useful than reassurance. The framework gives you a strong first hour; the remaining years are yours.

Sources

Every claim in this article is linked to the document it came from. Survey years and scopes are stated where they matter.

  1. ASP.NET Core security documentation, Microsoft Learn — accessed 2026.
  2. Antiforgery docs, Microsoft Learn — updated 2026.
  3. Identity docs, Microsoft Learn — updated 2026.
  4. Authorization docs, Microsoft Learn — updated 2026.
  5. OWASP Top 10 2025 — accessed 2026.
  6. OWASP Top Ten project — accessed 2026.