---
title: clsContext
summary: API reference for clsContext.
status: draft
owner: SAIF Documentation Team
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
---

# clsContext

`clsContext` is the cross-request/cross-application state bag every `clsModelBase` carries. It holds the business hand-off values (claim ID, policy number, SAIF claim number, provider location sequence number) a page needs to survive both postbacks and navigation to a different SAIF web application, and owns a private, direct-ADO.NET repository (`clsContextRepository`/`clsSQL`) that persists those values to a SQL Server `Context` table rather than using the standard BOF `IBusinessCriteria` pattern.

## Purpose
- Stores arbitrary named context values in an in-memory hashtable (`SetContext`/`GetContext`) for the duration of a request/session.
- Persists and retrieves those values across application boundaries via `SaveContext`/`RetrieveContext`, backing [BR-MVC-005](../../business-rules.md#br-mvc-005-cross-application-context-transfer-only-across-distinct-applications).
- Resolves a session's "page ID" (`SAIFPID_NAME`) via `GetPID`, used by `clsControllerBase.CheckContextViewID()`.
- Carries the current `clsSecurityPrincipal` for the request, consumed by `clsControllerBase.SecurityCheck()`.

## Context
- Namespace: `SAIF.Presentation.Web.MVC`
- Assembly/package: `SAIF.BOF.Presentation.Web.Infragistics103` (source-bundled)

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| `ApplicationName` | `Friend Property ApplicationName() As String` | Application name this context instance is scoped to; used as the `AppName` key for all `Context` table rows this instance saves/deletes. |
| `claimId` | `Public Property claimId() As Decimal` | Claim identifier hand-off value, backed by the `"claimId"` context key. |
| `policyNum` | `Public Property policyNum() As Integer` | Policy number hand-off value, backed by the `"policyNum"` context key. |
| `SAIFClaimNum` | `Public Property SAIFClaimNum() As String` | SAIF claim number hand-off value, backed by the `"SAIFClaimNum"` context key; initialized to `""` in both constructors. |
| `ProviderLocationSeqNum` | `Public Property ProviderLocationSeqNum() As Integer` | Provider location sequence number hand-off value, backed by the `"ProviderLocationSeqNum"` context key. |
| `SecurityPrincipal` | `Public Property SecurityPrincipal() As clsSecurityPrincipal` | Holds the authenticated principal for the current request once `clsControllerBase.SecurityCheck()` resolves it. |
| `UserName` | `Public ReadOnly Property UserName() As String` (marked `Obsolete`) | Returns the security principal's username as-cased; deprecated in favor of `UserID`. |
| `UserID` | `Public ReadOnly Property UserID() As String` | Returns the security principal's username, upper-cased; `""` if no principal is set. |
| `New()` | `Public Sub New()` | Initializes the internal hashtable and seeds `"SAIFClaimNum"` to `""`. |
| `New(inAppName)` | `Public Sub New(ByVal inAppName As String)` | Same as the parameterless constructor, additionally setting `ApplicationName`. |
| `GetContext` | `Public Function GetContext(ByVal key As String) As String` | Returns the in-memory value for `key`, or `Nothing` if not set. |
| `SetContext` | `Public Sub SetContext(ByVal key As String, ByVal value As String)` | Sets/overwrites the in-memory value for `key`. |
| `RetrieveContext` | `Protected Friend Function RetrieveContext(ByVal SourceAppName As String, ByVal CurrentAppName As String, ByVal inSessionID As String) As Hashtable` | Reads context rows left by `SourceAppName` for `inSessionID` (excluding rows already belonging to `CurrentAppName`) via [SQL-MVC-002](../../sql/SQL-MVC-002-retrieve-cross-application-context.md), then deletes them via [SQL-MVC-004](../../sql/SQL-MVC-004-delete-context-rows.md); returns the values as a `Hashtable` keyed by `ContextName`. |
| `SaveContext` | `Protected Friend Sub SaveContext(ByVal inSessionID As String)` | Deletes any prior rows for `ApplicationName`/`inSessionID` via [SQL-MVC-004](../../sql/SQL-MVC-004-delete-context-rows.md), then inserts one row per in-memory context key via [SQL-MVC-001](../../sql/SQL-MVC-001-insert-context-value.md) — a delete-then-reinsert "upsert via replace" pattern. |
| `GetPID` | `Protected Friend Function GetPID(ByVal inSessionID As String, ByVal inContextName As String) As String` | Looks up a single named context value via [SQL-MVC-003](../../sql/SQL-MVC-003-retrieve-single-context-value.md); returns `""` if no matching row is found. |

## Behavioral notes
- All ADO.NET access lives in a private nested class, `clsContextRepository`, and a private nested SQL-text provider, `clsSQL` — neither is part of this type's public surface, but their behavior is fully documented in the [SQL catalog](../../sql/index.md).
- `RetrieveContext` and `SaveContext` both wrap ADO.NET exceptions in an `ApplicationException` with a fixed message (e.g., `"Context Repository Retrieve Failed."`), preserving the original exception as `InnerException`.
- No `Update` operation exists against the `Context` table; `SaveContext` always deletes then re-inserts rather than updating in place.

## Constraints and usage notes
- `ApplicationName` is `Friend`-scoped (assembly-internal), so consuming applications outside this assembly cannot read/set it directly; it is populated by `clsControllerBase`'s constructor via `Model.Context.ApplicationName = m_ApplicationName`.
- `RetrieveContext`, `SaveContext`, and `GetPID` are `Protected Friend` — intended to be called only from within this library (primarily `clsControllerBase`), not directly by consuming application code.

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- SAIF.Presentation.Web.MVC\clsContext.vb
