---
title: Receive inbound cross-application context
summary: Retrieves and applies context left by a source application, completing a deferred navigation if one was requested.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-08-17
library: SAIF.Presentation.Web.MVC
reference_type: package
operation_id: OP-MVC-05
trigger: Initialize a request, step 10, when a referrer is present
---

# Receive inbound cross-application context

The receiving side of the cross-application hand-off. When a request arrives with a referrer from a different SAIF application, this operation reads and consumes the context rows that application saved, applies them through the derived screen's `HandleContext` hook, and completes any deferred navigation.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-MVC-05 |
| **Trigger** | Step 10 of [Initialize a request](initialize-request.md), when a referrer exists |
| **Inputs** | Referrer path, current request path |
| **Outputs** | Applied context via the derived `HandleContext`; a possible immediate `Navigate` |
| **Primary components** | `clsControllerBase.CheckContext` |
| **Entry point** | SAIF.Presentation.Web.MVC/clsControllerBase.vb |

## Steps

1. Extract the source application from the referrer path and the current application from the request path.
2. If they differ, call `Model.Context.RetrieveContext(sourceApp, currentApp, Session.SessionID)` ([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)).
   - Embeds [Retrieve and consume context rows](retrieve-context-rows.md): `SELECT` the source application's rows ([SQL-002](../sql/SQL-002-retrieve-context-rows.md), [Context](../database-tables.md#context)), then `DELETE` them so the hand-off is single-use ([SQL-004](../sql/SQL-004-delete-context-rows.md)).

> **Origin**: Step 2's retrieval and deletion are implemented in [`Retrieve and consume context rows`](retrieve-context-rows.md) (`clsContext.RetrieveContext`, this library) and executed on behalf of this operation.
   - If the applications match (no cross-app referrer): no context processing occurs for this request.
3. If any values were returned, call the derived `HandleContext(values)` so the screen applies them.
4. If the returned values contain a non-empty `targetView`, immediately call [Navigate to a view](navigate-to-view.md) with `(targetApp, targetView)` — completing a deferred navigation initiated by the source application ([BR-MVC-010](../business-rules.md#br-mvc-010-every-navigation-records-sourcetarget-app-and-view)).
   - If `targetView` is empty: no further navigation occurs; the request continues rendering the current view with the applied context.

Also called from `clsContext.GetPID` in the context of resolving a returning `__SAIFPID` view ID via [SQL-003](../sql/SQL-003-retrieve-context-value-by-name.md), used to rejoin a request to the correct multi-model instance ([BR-MVC-008](../business-rules.md#br-mvc-008-multi-model-view-state-is-keyed-by-a-per-view-guid)).

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([CheckContext referrer]) --> D1{Source app <> current app?}
	D1 -->|No| EndSkip([No context processing])
	D1 -->|Yes| S1[RetrieveContext: SELECT then DELETE rows]
	S1 --> D2{Values returned?}
	D2 -->|No| EndNone([Continue rendering])
	D2 -->|Yes| S2[Derived HandleContext applies values]
	S2 --> D3{targetView present?}
	D3 -->|Yes| S3([Navigate to targetApp/targetView])
	D3 -->|No| EndOk([Continue rendering current view])
```

## Failure and edge-case behavior
- Retrieval failures inside the repository are wrapped as `ApplicationException("Context Repository Retrieve Failed.")` after being traced (see [Retrieve and consume context rows](retrieve-context-rows.md)).
- Because rows are deleted immediately after retrieval, a refresh of the receiving page cannot replay the same hand-off.

## 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
