Cookie and session helpers¶
Three small helpers handle storage details so the page models do not touch cookies and session JSON directly: CookieService, ContextCookieHelperService, and the session extension methods.
| Field | Value |
|---|---|
| Operation ID | OP-16 |
| Trigger | Calls from page models and services |
| Inputs | Keys, values, timeout in seconds, ContextCookie |
| Outputs | Stored or retrieved values |
| Primary components | CookieService, ContextCookieHelperService, BolServiceSessionExtensions, SessionExtensions |
| Entry point | src/BolMiddleware/Services/CookieService/CookieService.cs |
Steps¶
SetCookieappends a cookie with HttpOnly set and an expiry of the supplied number of seconds from the local clock;SetCookieObjectserializes the object to JSON first (BR-BOLMIDDLEWARE-004).GetCookie,GetCookieObject, andDoesCookieExistread from the request cookie collection;DeleteCookieremoves the cookie.ContextCookieHelperServiceadds, removes, reads, and tests entries inContextCookie.userSettings; a null key or value throwsArgumentNullException.SetObjectandGetObject<T>serialize session values with Newtonsoft JSON;SaveWebContext,SaveMenu, andSavePolicyHeaderstore under theWebContextKey,WebContextId,BolMenu, andBolPolicyHeaderkeys.- If the session value is empty or cannot be deserialized to a value:
GetObject<T>returns the default value.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Helper call]) --> D1{Storage type?}
D1 -->|Cookie| S1[CookieService]
D1 -->|User setting| S2[ContextCookieHelperService]
D1 -->|Session| S3[Session extensions]
S1 --> EndOk([Value stored or returned])
S2 --> EndOk
S3 --> EndOk
Failure and edge-case behavior¶
- Cookies are written without Secure or SameSite attributes.
- Session objects use JSON text, so type changes between package versions can produce default values for older sessions.
Related documentation¶
- Index
- Overview
- Architecture
- Dependencies
- Configuration
- Operations and processes
- Business rules
- Security and authorization
- Service registration
- API reference
Sources¶
- src/BolMiddleware/Services/CookieService/CookieService.cs
- src/BolMiddleware/ContextCookieHelper/ContextCookieHelper.cs
- src/BolMiddleware/Extensions/BolMiddlewareExtensions.cs
- src/BolMiddleware/Contracts/Constants.cs