---
title: Cross-application context hand-off
summary: Merges context values left by a prior application into the current model when arriving via a cross-application referrer.
status: draft
owner: SAIF Documentation Team
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
operation_id: OP-MVC-002
trigger: clsControllerBase.CheckContext (referrer present)
---

# Cross-application context hand-off

When a user navigates into an application from a different SAIF application, this operation reads the context values the source application persisted to the shared `Context` table, merges them into the current request, consumes (deletes) them, and optionally continues navigation to a specific target view.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-MVC-002 |
| **Trigger** | `clsControllerBase.CheckContext(inAppPath)`, called from step 9 of [Page/control lifecycle initialization](page-control-lifecycle-initialization.md) when `Request.UrlReferrer` is present |
| **Inputs** | Referring URL path, current session ID |
| **Outputs** | Merged context values (via the abstract `HandleContext` hook), possible navigation |
| **Primary components** | `clsControllerBase.CheckContext`, `clsContext.RetrieveContext`, `clsContext.clsContextRepository` |
| **Entry point** | SAIF.Presentation.Web.MVC\clsControllerBase.vb |

## Steps

1. Derive `SourceAppName` from the referrer path and `CurrentAppName` from the current request path.
2. If `SourceAppName` and `CurrentAppName` differ (case-insensitively) ([BR-MVC-005](../business-rules.md#br-mvc-005-cross-application-context-transfer-only-across-distinct-applications)), call `Model.Context.RetrieveContext(SourceAppName, CurrentAppName, SessionID)`:
   - Executes [SQL-MVC-002](../sql/SQL-MVC-002-retrieve-cross-application-context.md) against [Context](../database-tables.md#context) to select all rows for `SourceAppName`/`SessionID` that do not already belong to `CurrentAppName`.
   - Immediately deletes the source application's rows via [SQL-MVC-004](../sql/SQL-MVC-004-delete-context-rows.md) against [Context](../database-tables.md#context) — a read-then-consume pattern with no rowcount/contention validation.
3. If any context values were returned, call the abstract `HandleContext(contextValues)` hook.
   - This hook's concrete implementation lives entirely in the consuming application; no further step tracing is possible from this library alone.
4. If a `targetView` context value is present among the retrieved values, call [Cross-application navigation](cross-application-navigation.md)'s `Navigate(targetApp, targetView)` to redirect into the resolved destination.

## Process flow

```mermaid
flowchart TD
	Start([CheckContext called]) --> Compare{SourceApp <> CurrentApp?}
	Compare -->|No| End([No hand-off; return])
	Compare -->|Yes| Retrieve[RetrieveContext: SQL-MVC-002 SELECT]
	Retrieve --> Delete[Delete source rows: SQL-MVC-004]
	Delete --> HasValues{Any context values returned?}
	HasValues -->|No| End
	HasValues -->|Yes| HandleContext[HandleContext hook - concrete controller]
	HandleContext --> TargetView{targetView value present?}
	TargetView -->|Yes| Navigate([Navigate to target app/view])
	TargetView -->|No| End
```

## Failure and edge-case behavior
- No rowcount validation occurs before the delete step — if the read returns zero rows, the delete still executes (a no-op `DELETE` with no matching rows).
- `HandleContext` is an abstract (`MustOverride`) hook; if the concrete controller's implementation throws, the exception propagates up to `ViewPageBase.Page_Error` → [Error handling](error-handling.md).
- ADO.NET failures inside `clsContextRepository.Retrieve`/`Delete` are wrapped in an `ApplicationException` with a fixed message and the original exception preserved as `InnerException`.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

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