Cross.Headers
1.1.0
dotnet add package Cross.Headers --version 1.1.0
NuGet\Install-Package Cross.Headers -Version 1.1.0
<PackageReference Include="Cross.Headers" Version="1.1.0" />
<PackageVersion Include="Cross.Headers" Version="1.1.0" />
<PackageReference Include="Cross.Headers" />
paket add Cross.Headers --version 1.1.0
#r "nuget: Cross.Headers, 1.1.0"
#:package Cross.Headers@1.1.0
#addin nuget:?package=Cross.Headers&version=1.1.0
#tool nuget:?package=Cross.Headers&version=1.1.0
Cross.Headers

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 inIHeadersContextAccessorwhen headers are missing (SystemId, BusinessId, LanguageCode, CurrencyCode, etc.).UserHeadersMiddleware— uses the already populated access token/claims and extracts user data fromHttpContext.User(Id, UserName, IsUser flag, scopes, etc.), writing it toIHeadersContextAccessor.
| Product | Versions 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. |
-
net10.0
- Microsoft.AspNetCore.Authentication.OpenIdConnect (>= 10.0.3)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.3)
-
net6.0
- Microsoft.AspNetCore.Authentication.OpenIdConnect (>= 6.0.25)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.IdentityModel.JsonWebTokens (>= 6.35.0)
- System.IdentityModel.Tokens.Jwt (>= 6.35.0)
-
net7.0
- Microsoft.AspNetCore.Authentication.OpenIdConnect (>= 7.0.20)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
-
net8.0
- Microsoft.AspNetCore.Authentication.OpenIdConnect (>= 8.0.24)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.3)
-
net9.0
- Microsoft.AspNetCore.Authentication.OpenIdConnect (>= 9.0.13)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.3)
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.