Skip to content

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

  1. Guard filterContext is not null (Enforce.ArgumentNotNull); throws on null (BR-01).
  2. If TempData contains key WebContextId, take the context id from TempData (BR-02).
  3. Otherwise read the context id from the request via HttpContextExtensions.GetWebContextId — form field WebContextId first, then query-string cid, else empty string (BR-03).
  4. If a non-blank context id was found, resolve it: webContextService.Get(webContextId) (delegates to OP-04).
  5. 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).
  6. Otherwise create a brand-new context: webContextService.Get() (delegates to OP-03).
  7. If the request carries a non-blank WebContextValue form/query value, overwrite WebContext.CurrentValue with it (BR-05).
  8. If WebContext.CurrentValue is non-blank, append Context={value} to the response log (Response.AppendToLog).
  9. 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 filterContext throws from Enforce.
  • Failures inside the WCF-backed webContextService calls propagate and are subsequently caught by HandleExceptionAttribute (OP-08).

Sources

  • src/Web.Mvc/Controllers/WebContextControllerBase.cs