BolContextModel¶
Abstract Razor PageModel at the base of the BOL page model chain. For each request it resolves the BOL web context, detects whether the user is external, and saves the context back after the handler runs. BolMenuModel and BolPolicyModel build on it.
Purpose¶
- Resolve the web context from the form, query string, session, cookie, or a new context (BR-BOLMIDDLEWARE-001).
- Save the context only when it changed or a save is forced, and only when it has content (BR-BOLMIDDLEWARE-002, BR-BOLMIDDLEWARE-003).
- Maintain the short-lived
BolContextcookie (BR-BOLMIDDLEWARE-004). - Capture external user information once per context (BR-BOLMIDDLEWARE-005, BR-BOLMIDDLEWARE-006).
- Choose the session id source (BR-BOLMIDDLEWARE-020).
Context¶
- Namespace:
BolMiddleware.Models - Assembly/package:
BolMiddleware
Public members¶
| Member | Signature | Purpose |
|---|---|---|
| Constructor | BolContextModel(IBolServicesContainer services) |
Receives the services container and builds the request helper from the current request. |
Services |
protected IBolServicesContainer Services |
Access to security, logging, context, menu, configuration, environment, and cookie services for derived pages. |
RequestHelper |
protected IRequestHelper RequestHelper |
Reads context id, session id, and form values from the current request. |
MyApplicationName |
protected string MyApplicationName |
Application name read from the required ApplicationName configuration value. |
PageName |
string PageName { get; protected set; } |
Page identifier used to mark the current menu item. |
ContextValue |
string ContextValue |
Text typed into the context textbox and posted with the form. |
contextCookie |
ContextCookie contextCookie |
Deserialized BolContext cookie for the current request. |
WebContext |
ContextHelper WebContext { get; protected set; } |
Working web context for the page: policy, claim, and related values. |
SaveContext |
protected void SaveContext(bool forceSave = false) |
Persists the context through IWebContextService and session when it changed or forceSave is true. |
OnContextSave |
virtual void OnContextSave() |
Hook that derived pages override to run logic before a context save. |
Navigate |
protected IActionResult Navigate(NavigationOptions options) |
Saves the context and redirects to the URL built from the options with the context id appended. |
OnPageHandlerSelected |
override void OnPageHandlerSelected(PageHandlerSelectedContext context) |
Initializes the context before the handler is chosen. |
OnPageHandlerExecuting |
override void OnPageHandlerExecuting(PageHandlerExecutingContext context) |
Reads the environment keys, resolves the context, and captures external user information. |
OnPageHandlerExecuted |
override void OnPageHandlerExecuted(PageHandlerExecutedContext context) |
Saves the context after the handler completes. |
Behavioral notes¶
- Failures in context resolution degrade to an empty context instead of throwing (BR-BOLMIDDLEWARE-021).
- The external user lookup blocks on an async call through
Task.Result.
Constraints and usage notes¶
- The cookie is deserialized without a signature; see Security and authorization.
- Requires the
ApplicationNameconfiguration key and the twobolmiddleware:environment keys (Configuration).
Sources¶
- src/BolMiddleware/Models/BolContextModel.cs