Save web context¶
Consumer pages call SaveContext after changing the context, and navigation calls it before leaving an application. The operation keeps the three context stores aligned while avoiding a remote call on every request.
| Field | Value |
|---|---|
| Operation ID | OP-06 |
| Trigger | SaveContext call from a page or navigation |
| Inputs | forceSave flag, current WebContext |
| Outputs | Updated BolContext cookie, session copy, and optionally the remote record |
| Primary components | BolContextModel.SaveContext, WebContextService.SaveContext, BolServiceSessionExtensions.SaveWebContext |
| Entry point | src/BolMiddleware/Models/BolContextModel.cs |
Steps¶
- Call the virtual
OnContextSavehook so the consumer can add items to the context before it is written. - If the context has content, write it to the
BolContextcookie with a ten second lifetime (BR-BOLMIDDLEWARE-003, BR-BOLMIDDLEWARE-004). - If
forceSaveis true or the target application differs from the current application, callWebContextService.SaveContextto persist through the BOL Context API (BR-BOLMIDDLEWARE-002). - On API failure: the service logs the error and returns false.
- Always save the context to the session through
SaveWebContext, which also stores the context id.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([SaveContext]) --> S1[OnContextSave hook]
S1 --> D1{Has content?}
D1 -->|Yes| S2[Write BolContext cookie]
D1 -->|No| D2
S2 --> D2{forceSave or different application?}
D2 -->|Yes| S3[Save through BOL Context API]
D2 -->|No| S4
S3 --> S4[Save to session]
S4 --> EndOk([Done])
Failure and edge-case behavior¶
- A failed API save does not stop the cookie or session writes and does not surface to the page (BR-BOLMIDDLEWARE-021).
- The cookie has no Secure or SameSite attribute and its expiry uses the local server time.
Related documentation¶
- Index
- Overview
- Architecture
- Dependencies
- Configuration
- Operations and processes
- Business rules
- Security and authorization
- Service registration
- API reference
Sources¶
- src/BolMiddleware/Models/BolContextModel.cs
- src/BolMiddleware/Services/Context/WebContextService.cs
- src/BolMiddleware/Extensions/BolMiddlewareExtensions.cs
- src/BolMiddleware/Services/CookieService/CookieService.cs