Skip to content

Request Hooks

Menu: Settings -> Request Hooks (advanced menu)
List: /_Admin/system/front-events?SiteId={siteGuid}
Edit: /_Admin/system/front-events/edit?SiteId={siteGuid}&name={eventName}&display={displayName}

Request Hooks run KScript rules at fixed points in the visitor HTTP request lifecycle (before/after route, page, view resolution) for URL rewrite, conditional redirects, dynamic page/view replacement, etc. Maps to BusinessRule + FrontEvent; requires site enableFrontEvents on.

Permissions

ActionPermission
View hook list and edit pagefrontEvents
New Hook, edit rules, Save, list Hook switchfrontEvents·edit
Multi-select Delete all rules for an eventList delete (removes all rules for that event type)

Master switch

Besides Hook On on this page, Request Hooks (enableFrontEvents) in Basic Settings · Advanced must be on; either off disables all request hooks.

Distinction from Action Hooks

Request Hooks (this page)Action Hooks
When they runFront-end HTTP requests (Route / Page / View)Backend save, delete, etc. on resources
Path/system/front-events/system/backend-events
Master switchenableFrontEventsenableBackendEvents

How to Open

  1. In Edit Menu, enable Settings -> Request Hooks.
  2. Open Settings -> Request Hooks in the left sidebar.
Request hooks list

Toolbar

ControlDescription
New HookOpens hook type picker (configured event types hidden)
Hook On / OffenableFrontEvents; toggling saves site immediately (saveSite)
Status textOn: “Hook On” (blue); off: gray “Hook Off”
Request hooks toolbar

Hook List

ColumnDescription
TypeLocalized event name (e.g. RouteFinding; wording per login language)
Rule countSaved rules for that event
EditOpens rule edit page

Multi-select Delete removes all rules for selected events (BusinessRule/DeleteEvents), not single rules.

Request hooks list

New Hook

Click New Hook for Hook list grouped by category (Route / View / Page); click a type to open edit page (row may appear only after save).

Hook type picker

Available Event Types

CategoryEvent name (name)Typical timing
RouteRouteFindingBefore route resolution (can change k.event.url, etc.)
RouteFoundRoute matched
RouteNotFoundNo route match
ViewViewFindingBefore view lookup
ViewFoundView found
ViewNotFoundView not found
PagePageFindingBefore page lookup
PageFoundPage found

Display names localized via Hardcoded; use BusinessRule/EventList as source of truth.

Rule Edit Page

Breadcrumb: Request Hooks -> {event display name}. No sidebar item; deep link needs name (required) and display (breadcrumb).

Rule edit page

New Rule

New Rule dropdown:

TypeValueStructure
IF-ELSE-THENIF-ELSE-THENIF + THEN / ELSE (nested rules)
DODOOne or more Code blocks in sequence

Default on empty edit page: one IF-ELSE-THEN rule.

Rule Cards

  • Drag handle on title bar for execution order within the event.
  • Delete on title bar removes the whole rule.

IF-ELSE-THEN

AreaDescription
IFOpens condition editor; conditions shown with &&
THEN / ELSENested rules; add IF-ELSE-THEN or DO

DO

Code snippet summaries; + add, pencil edit. Monaco KScript (language: typescript, KScript mode).

Code edit dialog

Example variables in editor comments (vary by event):

  • Common: k.event.url, k.event.userAgent, k.event.culture
  • Route: k.event.page, k.event.view, k.event.route

Example in RouteFinding: rewrite URL: k.event.url = "/pageone" (valid only in that event).

Edit Conditions

Edit conditions
ColumnDescription
Left valueFields for current event (BusinessRule/ConditionOption)
OperatorVaries (e.g. ==, contains)
Right valueConstant or expression fragment

+ adds rows; confirm writes rule if array. Runtime: ConditionManager.Evaluate.

Save and Leave

Bottom KBottomBar: Back to list; Save calls BusinessRule/post (eventName + rules). Unsaved changes prompt (useSaveTip).

Execution Order (Concept)

  1. Site enableFrontEvents is true.
  2. Request enters FrontEvent (e.g. RouteFinding).
  3. Rules run in list order; IF-ELSE-THEN then DO as described.

Execution is handled by the site's front-end request hook engine, in the order configured on this page.

Typical Workflow

  1. Confirm Advanced tab and Hook On here.
  2. New Hook → e.g. RouteFinding.
  3. Add IF-ELSE-THEN or DO, conditions and Code.
  4. Save, verify on front end with target URL.
  5. Collaborative export: BusinessRule in site package.
DocDescription
Settings overviewMenu and sub-routes
Basic Settings · AdvancedenableFrontEvents
Action HooksBackend operation events
Development -> CodeKScript code resources