---
title: HttpContextExtensions
summary: API reference for HttpContextExtensions.
status: draft
owner: bendy
last_reviewed: 2026-09-15
library: SAIF.Web.API.Clients
reference_type: package
---

# HttpContextExtensions

`HttpContextExtensions` is a static extension-method class that normalizes an ambient ASP.NET user's identity name to a bare account name, stripping a down-level domain prefix or UPN suffix. `JsonHttpClient` uses it internally to build the `OnBehalfOfUser` header, and it is also directly callable by consumers.

## Purpose
- Normalize `HttpContext.User.Identity.Name` to a bare account name by removing a `DOMAIN\` prefix or `@domain` suffix, so downstream APIs receive an unqualified account name ([BR-CLI-004](../../business-rules.md#br-cli-004-forwarded-user-name-normalization)). See [DomainlessUser](../../operations/domainless-user.md).

## Context
- Namespace: `SAIF.Web.API.Clients.Extensions`
- Assembly/package: `SAIF.Web.API.Clients` (NuGet package `SAIF.Web.API.Clients`)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| `DomainlessUser` | `static string DomainlessUser(this HttpContext httpContext)` | Reads `httpContext.User.Identity.Name`, strips a `DOMAIN\` prefix (when the separator index is `> 1`) and an `@domain` suffix (when its index in the original string is `> 1`), and returns the normalized name. |

## Behavioral notes
- Throws `NullReferenceException` if `httpContext`, `User`, `Identity`, or `Name` is `null` — there is no guard. For an unauthenticated request, `Name` is `""`.
- A separator at index 0 or 1 (for example a name beginning `A\user`) is not stripped, because the threshold is `> 1`, not `>= 0`.
- The `@` index is computed on the original string before the `\`-prefix substring is taken; a name containing both separators (for example `DOMAIN\user@domain`) can be truncated incorrectly as a result.

## Constraints and usage notes
- This extension method requires an ambient ASP.NET request context; it is not usable from a non-web host (console/service) without one.

## Sources
- `src/SAIF.Web.API.Clients/Extensions/HttpContextExtensions.cs`
