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

# clsContext

`clsContext` is the named key/value context bag every `clsModelBase` carries, combining well-known typed properties (`claimId`, `policyNum`, `SAIFClaimNum`, `ProviderLocationSeqNum`) with a generic string `GetContext`/`SetContext` store, the established `clsSecurityPrincipal`, and the SQL Server-backed repository (its private nested `clsContextRepository`) that transfers context values between SAIF applications during cross-application navigation. It is the object [Persist context rows](../../operations/persist-context-rows.md) and [Retrieve and consume context rows](../../operations/retrieve-context-rows.md) operate on, and its `UserID` property is the source of the identity used to load a user's authorized menu ([BR-MVC-015](../../business-rules.md#br-mvc-015-menu-authorization-data-is-read-from-oracle-as-user-menu)).

## Purpose
- Holds the current security principal and well-known screen fields (claim, policy, provider-location identifiers) shared across a screen's model and controller.
- Provides a generic string key/value store (`GetContext`/`SetContext`) for arbitrary context values a screen or the navigation pipeline needs to carry.
- Persists, retrieves, and deletes context rows in the SQL Server `Context` table so a value set in one SAIF application can be read by another after a cross-application navigation ([BR-MVC-010](../../business-rules.md#br-mvc-010-every-navigation-records-sourcetarget-app-and-view), [BR-MVC-017](../../business-rules.md#br-mvc-017-cross-application-context-is-consumed-exactly-once)).
- Derives the authorization identity (`UserID`) used to load a user's authorized menu set, from the established `SecurityPrincipal`.

## Context
- Namespace: `SAIF.Presentation.Web.MVC`*
- Assembly/package: `SAIF.Presentation.Web.MVC`

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| `claimId` | `Public Property claimId() As Decimal` | Well-known context field carrying the current claim identifier |
| `policyNum` | `Public Property policyNum() As Integer` | Well-known context field carrying the current policy number |
| `SAIFClaimNum` | `Public Property SAIFClaimNum() As String` | Well-known context field carrying the SAIF-formatted claim number |
| `ProviderLocationSeqNum` | `Public Property ProviderLocationSeqNum() As Integer` | Well-known context field carrying a provider location sequence number |
| `SecurityPrincipal` | `Public Property SecurityPrincipal() As clsSecurityPrincipal` | The authenticated identity established for the current request by `clsControllerBase.SecurityCheck` |
| `UserName` | `Public ReadOnly Property UserName() As String` | Legacy accessor for the current user's name, derived from `SecurityPrincipal` |
| `UserID` | `Public ReadOnly Property UserID() As String` | Returns `SecurityPrincipal.UserName.ToUpper()`, or an empty string when no principal is set; the identity used to load the authorized menu set ([BR-MVC-015](../../business-rules.md#br-mvc-015-menu-authorization-data-is-read-from-oracle-as-user-menu)) |
| `GetContext` | `Public Function GetContext(ByVal key As String) As String` | Reads a generic named context value previously set with `SetContext` |
| `SetContext` | `Public Sub SetContext(ByVal key As String, ByVal value As String)` | Writes a generic named context value into the in-memory context bag |
| `ApplicationName` | `Friend Property ApplicationName() As String` | The application name this context belongs to; set by the controller during model construction |
| `RetrieveContext` | `Protected Friend Function RetrieveContext(ByVal SourceAppName As String, ByVal CurrentAppName As String, ByVal inSessionID As String) As Hashtable` | Reads and deletes the source application's saved context rows for this session, returning them as a hashtable; see [Retrieve and consume context rows](../../operations/retrieve-context-rows.md) |
| `SaveContext` | `Protected Friend Sub SaveContext(ByVal inSessionID As String)` | Replaces this application/session's context rows with the current in-memory context values; see [Persist context rows](../../operations/persist-context-rows.md) |
| `GetPID` | `Protected Friend Function GetPID(ByVal inSessionID As String, ByVal inContextName As String) As String` | Resolves a single named context value (typically the `__SAIFPID` view ID) for the current application/session, used to rejoin a request to the correct multi-model instance |

## Behavioral notes
- `RetrieveContext` and `SaveContext` each construct their own `clsContextRepository` (a private nested class) and open a dedicated `SqlConnection` per database operation rather than sharing a connection across the call.
- `UserID`'s dependence on `SecurityPrincipal` means it returns an empty string for any context that has not yet been through a successful `SecurityCheck`.

## Constraints and usage notes
- `ApplicationName`'s setter is `Friend`, so only code within this assembly (the controller, during model/context construction) can change which application a context belongs to.
- The private nested `clsContextRepository` and `clsSQL` classes are not part of this type's public surface and are not separately documented in the API reference.

> **Note:** Statements marked with `*` were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

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