Cross.Headers 1.1.0

dotnet add package Cross.Headers --version 1.1.0
                    
NuGet\Install-Package Cross.Headers -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Cross.Headers" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cross.Headers" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Cross.Headers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Cross.Headers --version 1.1.0
                    
#r "nuget: Cross.Headers, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Cross.Headers@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cross.Headers&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Cross.Headers&version=1.1.0
                    
Install as a Cake Tool

Cross.Headers Nuget Documentation

ASP.NET Core middleware boilerplate for handling correlation id, security headers (CSP), and user context based on configuration and OpenIdConnect authentication. Provides IHeadersContextAccessor as a scoped service for request-scoped access to correlation id, system/business ids, language, currency, user-agent, and authenticated user data.

Supported frameworks: .NET 6, .NET 7, .NET 8, .NET 9, .NET 10

Install NuGet package

Install the package Cross.Headers NuGet package into your ASP.NET Core project:

Install-Package Cross.Headers

or

dotnet add package Cross.Headers

IHeadersContextAccessor

IHeadersContextAccessor is registered as a scoped service. Inject it via DI anywhere in your application (controllers, services, middleware) to access request-scoped context populated by the middleware pipeline. Within a single HTTP request, the same instance is shared across all consumers, so you get consistent correlation id, user data, and header-derived values for the entire request lifecycle.

public interface IHeadersContextAccessor
{
    Guid CorrelationId { get; set; }
    int SystemId { get; set; }
    int BusinessId { get; set; }
    string? LanguageCode { get; set; }
    string? CurrencyCode { get; set; }
    string? UserAgent { get; set; }
    UserAgentKindEnum UserAgentKind { get; set; }
    Guid UserId { get; set; }
    string? UserName { get; set; }
    string? UserAccessToken { get; set; }
    IReadOnlyCollection<Claim> UserClaims { get; set; }
    IReadOnlyCollection<string> UserPermissions { get; set; }
    IReadOnlyCollection<string> UserScopes { get; set; }
    bool IsUser { get; set; }
}

Library usage

Services registration

The recommended way to register services is to use the AddHeaders extension:

builder.Services.AddHeaders(builder.Configuration);

The AddHeaders method registers IHeadersContextAccessor as a scoped service and prepares the infrastructure for the middleware pipeline.

Also ensure that you configure OpenIdConnect authentication and set the LanguageDefault, CurrencyDefault, and CSPFrameAncestors values in your configuration.

Configure middleware

Add the middleware in this exact order:

// CORS MUST be before middleware that reads headers, so preflight (OPTIONS) requests are handled correctly
app.UseCors("UI");

// If your middleware reads headers and builds context — place it AFTER CORS, otherwise it will receive preflight requests
app.UseMiddleware<HeadersMiddleware>();
app.UseMiddleware<DefaultHeadersMiddleware>();

app.UseAuthentication();  // should be before UseMvc() call
app.UseMiddleware<UserHeadersMiddleware>();
app.UseAuthorization();   // should be before UseMvc() call

Cross.Headers middleware:

  • HeadersMiddleware — reads technical headers (correlation id, system/business id, language, currency, user-agent, access token, etc.), builds the main context, and adds technical headers to the response (e.g., correlation id and CSP).
  • DefaultHeadersMiddleware — fills default values in IHeadersContextAccessor when headers are missing (SystemId, BusinessId, LanguageCode, CurrencyCode, etc.).
  • UserHeadersMiddleware — uses the already populated access token/claims and extracts user data from HttpContext.User (Id, UserName, IsUser flag, scopes, etc.), writing it to IHeadersContextAccessor.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Cross.Headers:

Package Downloads
Cross.Identity

Identity and authentication library for .NET: configurable flows (registration, login, forgot password, token, refresh), JWT, Argon2, email/SMS verification, process engine with JSON-defined flows.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 33 3/7/2026
1.1.0-preview.3 31 3/7/2026
1.0.1 34 3/6/2026
1.0.1-preview.1 33 3/6/2026
1.0.0 195 2/24/2026

Initial version.