Resolve web context for an incoming request¶
Resolve and populate the request's web context before the action runs. Trigger: MVC action-filter pipeline, before every action on a derived controller.
| Field | Value |
|---|---|
| Operation ID | OP-01 |
| Trigger | MVC action-filter pipeline, before every action on a derived controller |
| Inputs | ActionExecutingContext (request form, query string, referrer, session), TempData |
| Outputs | WebContext protected property populated; Context= entry appended to the IIS log |
| Primary components | WebContextControllerBase.OnActionExecuting(ActionExecutingContext) |
| Entry point | src/Web.Mvc/Controllers/WebContextControllerBase.cs |
Steps¶
- Guard
filterContextis not null (Enforce.ArgumentNotNull); throws on null (BR-01). - If
TempDatacontains keyWebContextId, take the context id from TempData (BR-02). - Otherwise read the context id from the request via
HttpContextExtensions.GetWebContextId— form fieldWebContextIdfirst, then query-stringcid, else empty string (BR-03). - If a non-blank context id was found, resolve it:
webContextService.Get(webContextId)(delegates to OP-04). - Otherwise, if the request URL and referrer both have more than one segment and their first segments differ (arrival from a different application), resolve the referring application's context via
webContextService.Get(referrerApplicationName, Session.SessionID)(delegates to OP-05) (BR-04). - Otherwise create a brand-new context:
webContextService.Get()(delegates to OP-03). - If the request carries a non-blank
WebContextValueform/query value, overwriteWebContext.CurrentValuewith it (BR-05). - If
WebContext.CurrentValueis non-blank, appendContext={value}to the response log (Response.AppendToLog). - Call
base.OnActionExecuting(filterContext).
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start([Action filter pipeline])
TD[Check TempData for WebContextId]
FQ[Check form/query cid]
Ref[Check referrer application]
New[Create new context]
Over[Apply WebContextValue override]
Log[Append Context to IIS log]
EndOk([Continue to action])
Start --> TD
TD --> FQ
FQ --> Ref
Ref --> New
New --> Over
TD --> Over
FQ --> Over
Ref --> Over
Over --> Log
Log --> EndOk
Failure and edge-case behavior¶
- Null
filterContextthrows fromEnforce. - Failures inside the WCF-backed
webContextServicecalls propagate and are subsequently caught byHandleExceptionAttribute(OP-08).
Related documentation¶
Sources¶
src/Web.Mvc/Controllers/WebContextControllerBase.cs