MVC and pipelines

Current version: 9.0

This topic describes the pipelines and the processors Sitecore MVC uses.

MVC-specific processors

Some standard Sitecore pipelines have processors that are specifically used for Sitecore MVC. This table shows what they are:

Pipeline

Processors

Initialize

  • InitializeGlobalFilters – this processor sets up the following hooks in the MVC global filters:

    • ActionExecuting

    • ActionExecuted

    • ResultExecuting

    • ResultExecuted

    • Exception

  • InitializeControllerFactory – this processor installs a custom controller factory (IControllerFactory) into the MVC runtime to facilitate greater control over MVC request handling and controller creation.

  • InitializeRoutes – sets up the default Sitecore route handler (fall-through: {*pathInfo}) and decorates existing routes with Sitecore-specific route keys.

HttpBeginRequest

  • TransferRoutedRequest: This processor is placed before the LayoutResolver processor. If the request matches a route in the MVC route table, the pipeline stops executing and makes the MVC request handler take over. Only custom routes are considered. The Sitecore fall-through route ({*pathInfo}) is ignored by the processor (otherwise all requests would match and be processed by MVC).

  • TransferMvcLayout: This processor is placed after the LayoutResolver processor. If the resolved layout file name has an extension matching one of the extensions specified in the MvcSettings.ViewExtensions setting, the pipeline stops executing and makes the MVC request handler take over.

  • TransferControllerRequest: This processor is placed after the TransferMvcLayout processor. If no layout has been resolved, the Controller field of the current item is inspected. If it contains a value, the pipeline stops executing and makes the MVC request handler take over. The specified controller is then responsible for rendering the item.

MVC-specific pipelines

The following table lists all of the Sitecore pipelines that are only used by MVC:

Pipeline

Description

RequestBegin

This is the first action of an MVC request after the request has been passed down from the main HttpRequest pipeline.

A PageContext is created and assigned to the current thread.

If the request is a form post, the associated form handler (if any) is executed.

RequestEnd

This is the last action of an MVC request. This pipeline is not currently used.

CreateController

This pipeline is called by the SitecoreControllerFactory to create a controller for the current route selected by the MVC request handler.

If the requested item (PageContext.Item) specifies a controller (in the __Controller Name field), this controller is instantiated and returned. Otherwise, an instance of the default SitecoreController is returned.

ActionExecuting

This pipeline executes before an MVC controller action is executed. This pipeline is not currently used.

ActionExecuted

This pipeline executes after an MVC controller action is executed. This pipeline is not currently used.

ResultExecuting

This pipeline executes before an MVC result is executed. This pipeline is not currently used.

ResultExecuted

This pipeline executes after an MVC result is executed. This pipeline is not currently used.

Exception

This pipeline executes after the MVC runtime catches an unhandled exception. This pipeline is not currently used.

If you attach a custom processor to this pipeline, this processor should set the ExceptionContext.ExceptionHandled property on the ExceptionArgs object that is handed to the processor. Otherwise, Sitecore will do standard error handling.

GetPageItem

This pipeline resolves the item that was requested using route information. If the item cannot be resolved from the route, Context.Item is used.

BuildPageDefinition

This pipeline builds the initial PageDefinition by using the XML-based layout definition of the Renderings field on the page item.

GetPageRendering

This pipeline selects the rendering to use as the root rendering of the page for creating the output of the current request.

Currently, the root rendering is selected based solely on the current device (PageContext.Device).

GetRenderer

This pipeline transforms an abstract rendering definition (rendering) into an object that can render output back to the client (renderer).

GetModel

This pipeline creates the model object to use when rendering an MVC view. This is typically a ASP.NET MVC 3 Razor view.

If the pipeline returns no model, the view receives an instance of EmptyModel. This triggers a meaningful error message if the .cshtml file contains the @model directive and therefore expects a model.

RenderPlaceholder

This pipeline is called as part of the Html.Sitecore().Placeholder extension method. It handles nested placeholders, when applicable.

By default, the pipeline finds all renderings matching the specified placeholder name in the current PageDefinition and renders them. It only renders child renderings if the rendering explicitly renders them, typically by calling Html.Sitecore().Inner().

RenderRendering

The pipeline renders the specified rendering. This pipeline handles caching and sets up the IRenderingContext for accessing source items of the renderings. This supports nested renderings.

Do you have some feedback for us?

If you have suggestions for improving this article,