Introduction

edit

The Meziantou.AspNetCore.* packages add the pieces that most ASP.NET Core applications write again and again: production defaults for a web application, a few middleware, HTTP Basic authentication, tag helpers for MVC and Razor Pages, and Blazor components. Each package is independent: install only the ones you need.

The packages

PackageWhat it gives youDocumentation
Meziantou.AspNetCore.ServiceDefaultsOne call that configures OpenTelemetry, health checks, OpenAPI, HTTP client resilience, JSON conventions, HTTPS and other production defaultsService defaults
Meziantou.AspNetCore.ServiceDefaults.AutoRegisterA source generator that applies the service defaults to every WebApplicationBuilder.Build() call, so you don't write the two calls yourselfApplying the defaults automatically
Meziantou.AspNetCoreA middleware that marks responses as non-cacheable when they don't say otherwise, and a diagnostic view of the middleware pipelineMiddleware
Meziantou.AspNetCore.Authentication.HttpBasicAn authentication handler for HTTP Basic, with your own credential check or with ASP.NET Core IdentityHTTP Basic authentication
Meziantou.AspNetCore.MvcTag helpers for MVC and Razor Pages: conditional rendering, inlined CSS, scripts and images, deferred content, datetime attributesMVC tag helpers
Meziantou.AspNetCore.ComponentsBlazor components (repeater, data grid, infinite scrolling, generated forms, inputs) and browser services (clipboard, query string, time zone)Blazor components
Meziantou.AspNetCore.Components.LogViewerA Blazor component that displays log entries with highlighting, ANSI colors, structured payloads and nested entriesLog viewer
Meziantou.AspNetCore.Components.WebAssemblyA message handler that sets the browser fetch options (cache, credentials, mode) of every HttpClient request in Blazor WebAssemblyBrowser fetch options

Which package do I need?

  • A new web API or web application that should be ready for production: start with Meziantou.AspNetCore.ServiceDefaults. It already includes the no-cache middleware of Meziantou.AspNetCore. Add Meziantou.AspNetCore.ServiceDefaults.AutoRegister if you don't want to call the setup methods yourself.
  • Scripts, tools or devices that call your API with a username and a password: Meziantou.AspNetCore.Authentication.HttpBasic.
  • Server-rendered pages (MVC views or Razor Pages): Meziantou.AspNetCore.Mvc.
  • A Blazor application: Meziantou.AspNetCore.Components, plus Meziantou.AspNetCore.Components.LogViewer to show logs, and Meziantou.AspNetCore.Components.WebAssembly for a WebAssembly client that calls an API.
  • Debugging the order of your middleware: Meziantou.AspNetCore.

Principles

  • Opt-in pieces. Every component, middleware and service is added explicitly. The only exception is the auto-register generator, whose whole purpose is to add the service defaults for you.
  • Safe defaults. The pipeline debug endpoint answers only in Development, HTTP Basic rejects accounts that need a second factor, InputUrl rejects javascript: URLs, and the log viewer renders only http and https links.
  • Your settings win. The no-cache middleware never replaces a Cache-Control header you set, and the browser fetch handler never replaces an option set on a request.

Next steps

  • Getting started: install a package and see each one at work in a few lines.