November Happy Hour will be moved to Thursday December 5th.

Class PageRouteHelper

The PageRouteHelper class is used to provide access to information about the requested CMS page of the current web request.

Inheritance
System.Object
PageRouteHelper
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.Web.Routing
Assembly: EPiServer.dll
Version: 9.12.2
Syntax
public class PageRouteHelper : ContentRouteHelper, IPageRouteHelper, IContentRouteHelper
Remarks

The class is supported in both Web Forms and MVC.

PageRouteHelper is registred by the ServiceLocator in the InitializationModule, which makes it possible to create an instance of the class by the method GetInstance<TService>().

PageRouteHelper is used by PageBase to get the CurrentPageLink for a page.

MVC controls can inherit EPiServer.Web.Mvc.PageController{T} to get the property EPiServer.Web.Mvc.PageController{T}.PageContext, which is an instance of this class.

This class is thread safe.

Examples
  The following code example demonstrates how to get information about the requested CMS page for the current web request
using System.Text;
using EPiServer.Web.Routing;
using EPiServer.ServiceLocation;

namespace CodeSamples.Routing
{
/// <summary>
/// Code sample class containing cref examples on how PageRouteHelper can be used.
/// </summary>
public class PageRouteInformation
{
/// <summary>
/// Gets information about the requested CMS page for the current web request
/// </summary>
public string GetPageRouteInformation()
{
var routeHelper = ServiceLocator.Current.GetInstance<IPageRouteHelper>();

StringBuilder routePageStringBuilder = new StringBuilder();

// Gets the display name
routePageStringBuilder.AppendFormat("Page name: {0}. ", routeHelper.Page.PageName);

// Gets the page id
routePageStringBuilder.AppendFormat("Page link id: {0}. ", routeHelper.PageLink.ID);

// Gets the version
routePageStringBuilder.AppendFormat("Page version: {0}. ", routeHelper.PageLink.WorkID);

// Gets the language
routePageStringBuilder.AppendFormat("Language: {0}. ", routeHelper.LanguageID);


return routePageStringBuilder.ToString();
}
}
}

Constructors

PageRouteHelper(RequestContext, RouteCollection, IViewContentRetriever, IContentLoader)

Initializes a new instance of the PageRouteHelper class.

Declaration
public PageRouteHelper(RequestContext context, RouteCollection routes, IViewContentRetriever viewContentRetriever, IContentLoader contentLoader)
Parameters
Type Name Description
System.Web.Routing.RequestContext context

The context, which encapsulates information about an HTTP request that matches the defined route.

System.Web.Routing.RouteCollection routes

If the page hasn't been routed, the routing system will be called with the supplied routing collection to receive nessasary information about the current page.

IViewContentRetriever viewContentRetriever

The view content retriever.

IContentLoader contentLoader

The content loader

Remarks

The public properties in the class gets initialized for execution. Each value will be set the first time it gets called, and cached for the current instance.

PageRouteHelper is registred by the ServiceLocator in the InitializationModule, which makes it possible to create an instance of the class by the method GetInstance<TService>().

If the page hasn't been routed, the routing system will be called with the supplied routes to receive necessary information about the current page

Examples
  The following code example demonstrates how to get information about the requested CMS page for the current web request
using System.Text;
using EPiServer.Web.Routing;
using EPiServer.ServiceLocation;

namespace CodeSamples.Routing
{
/// <summary>
/// Code sample class containing cref examples on how PageRouteHelper can be used.
/// </summary>
public class PageRouteInformation
{
/// <summary>
/// Gets information about the requested CMS page for the current web request
/// </summary>
public string GetPageRouteInformation()
{
var routeHelper = ServiceLocator.Current.GetInstance<IPageRouteHelper>();

StringBuilder routePageStringBuilder = new StringBuilder();

// Gets the display name
routePageStringBuilder.AppendFormat("Page name: {0}. ", routeHelper.Page.PageName);

// Gets the page id
routePageStringBuilder.AppendFormat("Page link id: {0}. ", routeHelper.PageLink.ID);

// Gets the version
routePageStringBuilder.AppendFormat("Page version: {0}. ", routeHelper.PageLink.WorkID);

// Gets the language
routePageStringBuilder.AppendFormat("Language: {0}. ", routeHelper.LanguageID);


return routePageStringBuilder.ToString();
}
}
}

PageRouteHelper(RequestContext, RouteCollection, ViewContentRetriever, IContentLoader)

Declaration
[Obsolete("Use alternative constructor")]
public PageRouteHelper(RequestContext context, RouteCollection routes, ViewContentRetriever viewContentRetriever, IContentLoader contentLoader)
Parameters
Type Name Description
System.Web.Routing.RequestContext context
System.Web.Routing.RouteCollection routes
ViewContentRetriever viewContentRetriever
IContentLoader contentLoader

Properties

Page

Gets the current page.

Declaration
public virtual PageData Page { get; }
Property Value
Type Description
PageData
Remarks

The property will be set the first time it gets called, and cached for the current instance.

Examples
  The following code example demonstrates how to get information about the requested CMS page for the current web request.
using System.Text;
using EPiServer.Web.Routing;
using EPiServer.ServiceLocation;

namespace CodeSamples.Routing
{
/// <summary>
/// Code sample class containing cref examples on how PageRouteHelper can be used.
/// </summary>
public class PageRouteInformation
{
/// <summary>
/// Gets information about the requested CMS page for the current web request
/// </summary>
public string GetPageRouteInformation()
{
var routeHelper = ServiceLocator.Current.GetInstance<IPageRouteHelper>();

StringBuilder routePageStringBuilder = new StringBuilder();

// Gets the display name
routePageStringBuilder.AppendFormat("Page name: {0}. ", routeHelper.Page.PageName);

// Gets the page id
routePageStringBuilder.AppendFormat("Page link id: {0}. ", routeHelper.PageLink.ID);

// Gets the version
routePageStringBuilder.AppendFormat("Page version: {0}. ", routeHelper.PageLink.WorkID);

// Gets the language
routePageStringBuilder.AppendFormat("Language: {0}. ", routeHelper.LanguageID);


return routePageStringBuilder.ToString();
}
}
}

Gets the page link for the current page.

Declaration
public virtual PageReference PageLink { get; }
Property Value
Type Description
PageReference

Webform pages, inheriting from PageBase, can use the property CurrentPageLink instead of this class, to receive the PageReference of the current web request.

  The following code example demonstrates how to get information about the requested CMS page for the current web request.
using System.Text;
using EPiServer.Web.Routing;
using EPiServer.ServiceLocation;

namespace CodeSamples.Routing
{
/// <summary>
/// Code sample class containing cref examples on how PageRouteHelper can be used.
/// </summary>
public class PageRouteInformation
{
/// <summary>
/// Gets information about the requested CMS page for the current web request
/// </summary>
public string GetPageRouteInformation()
{
var routeHelper = ServiceLocator.Current.GetInstance<IPageRouteHelper>();

StringBuilder routePageStringBuilder = new StringBuilder();

// Gets the display name
routePageStringBuilder.AppendFormat("Page name: {0}. ", routeHelper.Page.PageName);

// Gets the page id
routePageStringBuilder.AppendFormat("Page link id: {0}. ", routeHelper.PageLink.ID);

// Gets the version
routePageStringBuilder.AppendFormat("Page version: {0}. ", routeHelper.PageLink.WorkID);

// Gets the language
routePageStringBuilder.AppendFormat("Language: {0}. ", routeHelper.LanguageID);


return routePageStringBuilder.ToString();
}
}
}

Implements

Extension Methods

See Also