Cross.Headers
1.3.0
dotnet add package Cross.Headers --version 1.3.0
NuGet\Install-Package Cross.Headers -Version 1.3.0
<PackageReference Include="Cross.Headers" Version="1.3.0" />
<PackageVersion Include="Cross.Headers" Version="1.3.0" />
<PackageReference Include="Cross.Headers" />
paket add Cross.Headers --version 1.3.0
#r "nuget: Cross.Headers, 1.3.0"
#:package Cross.Headers@1.3.0
#addin nuget:?package=Cross.Headers&version=1.3.0
#tool nuget:?package=Cross.Headers&version=1.3.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.
Target frameworks: net6.0, net7.0, net8.0, net9.0, net10.0
Features
AddHeaders— registersIHeadersContextAccessoras scoped.HeadersMiddleware— reads technical request headers into context and writes correlation id + CSP to the response.DefaultHeadersMiddleware— applies defaults when headers are missing (SystemId,BusinessId,CountryCode,LanguageCode,CurrencyCode).UserHeadersMiddleware— fills user id/name/scopes/claims fromHttpContext.User(after authentication).IHeadersContextAccessor.MapFrom— copies mapped context fields between accessors (includingUserClaims).
Install NuGet package
Install the Cross.Headers NuGet package into your .NET project:
Install-Package Cross.Headers
or
dotnet add package Cross.Headers
Request headers
| Header | Context property | Notes |
|---|---|---|
X-Correlation-Id |
CorrelationId |
Generated when missing or invalid |
X-System-Id |
SystemId |
Default 1 |
X-Business-Id |
BusinessId |
Default 1 |
X-Country-Code |
CountryCode |
ISO 3166-1 alpha-2 (e.g. UA, US); default from CountryDefault or US |
X-Language-Code |
LanguageCode |
ISO 639-1 (e.g. EN, RU, UK); Ukrainian language = UK, not UA |
X-Currency-Code |
CurrencyCode |
ISO 4217 (e.g. EUR, USD); default from CurrencyDefault or USD |
User-Agent |
UserAgent / UserAgentKind |
Detects Android/iOS app markers and mobile browsers |
Authorization |
UserAccessToken |
Optional Bearer prefix is stripped |
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.
public interface IHeadersContextAccessor
{
Guid CorrelationId { get; set; }
int SystemId { get; set; }
int BusinessId { get; set; }
string? CountryCode { 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
builder.Services.AddHeaders(builder.Configuration);
AddHeaders registers IHeadersContextAccessor as a scoped service.
Also configure OpenIdConnect authentication and set defaults in configuration:
{
"CountryDefault": "US",
"LanguageDefault": "EN",
"CurrencyDefault": "USD",
"CSPFrameAncestors": "'self'"
}
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() / MapControllers()
app.UseMiddleware<UserHeadersMiddleware>();
app.UseAuthorization(); // should be before UseMvc() / MapControllers()
Cross.Headers middleware:
HeadersMiddleware— reads technical headers (correlation id, system/business/country id, language, currency, user-agent, access token, etc.), builds the main context, and adds technical headers to the response (correlation id and CSP).DefaultHeadersMiddleware— fills default values inIHeadersContextAccessorwhen headers are missing (SystemId,BusinessId,CountryCode,LanguageCode,CurrencyCode).UserHeadersMiddleware— extracts user data fromHttpContext.User(UserId,UserName,IsUser, scopes/permissions, claims) intoIHeadersContextAccessor.
Release notes
See ReleaseNotes.txt and GitHub Releases.
Contributing
- Fork the repository.
- Create a feature branch (
git checkout -b feature/your-change). - Commit your changes with a clear message.
- Push the branch and open a pull request.
License
This project is licensed under the MIT License — see the LICENSE file for details.
| 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.5)
-
net6.0
- Microsoft.AspNetCore.Authentication.OpenIdConnect (>= 6.0.25)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
-
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 (>= 8.0.2)
-
net9.0
- Microsoft.AspNetCore.Authentication.OpenIdConnect (>= 9.0.13)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.14)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.3.0 | 166 | 11/2/2026 |
| 1.3.0-preview.2 | 52 | 11/2/2026 |
| 1.3.0-preview.1 | 58 | 11/2/2026 |
| 1.2.1 | 1,357 | 3/25/2026 |
| 1.2.0 | 229 | 3/25/2026 |
| 1.2.0-preview.9 | 96 | 3/25/2026 |
| 1.2.0-preview.8 | 89 | 3/25/2026 |
| 1.2.0-preview.7 | 91 | 3/25/2026 |
| 1.2.0-preview.6 | 94 | 3/25/2026 |
| 1.2.0-preview.5 | 82 | 3/25/2026 |
| 1.2.0-preview.4 | 88 | 3/25/2026 |
| 1.1.1 | 142 | 3/25/2026 |
| 1.1.1-preview.2 | 91 | 3/25/2026 |
| 1.1.0 | 141 | 3/7/2026 |
| 1.1.0-preview.3 | 95 | 3/7/2026 |
| 1.0.1 | 141 | 3/6/2026 |
| 1.0.1-preview.1 | 90 | 3/6/2026 |
| 1.0.0 | 407 | 2/24/2026 |
Added X-Country-Code / CountryCode and CountryDefault; README and tests updated.