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

Class RouteCollectionExtensions

Contains extension methods for System.Web.Routing.RouteCollection.

Inheritance
System.Object
RouteCollectionExtensions
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 static class RouteCollectionExtensions

Fields

GlobalAssetStaticSegment

Specifies the static segment that by default is used for global media.

Declaration
public const string GlobalAssetStaticSegment = "globalassets"
Field Value
Type Description
System.String

MediaStaticSegmentPlaceHolder

Specifies the placeholder for the static segment that will be exchanged for GlobalAssetStaticSegment or SiteAssetStaticSegment.

Declaration
public const string MediaStaticSegmentPlaceHolder = "MediaStaticPlaceHolder"
Field Value
Type Description
System.String

SiteAssetStaticSegment

Specifies the static segment that by default is used for site specific media.

Declaration
public const string SiteAssetStaticSegment = "siteassets"
Field Value
Type Description
System.String

Methods

GetVirtualPath(RouteCollection, ContentReference, String)

Returns the virtual path for the page as it is specified by the first matching route.

Declaration
[Obsolete("Use the methods in UrlResolver instead.", false)]
public static VirtualPathData GetVirtualPath(this RouteCollection routes, ContentReference contentLink, string language)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

ContentReference contentLink

The content reference for which to the virtual path.

System.String language

The language code that should be used when creating the virtual path.

Returns
Type Description
System.Web.Routing.VirtualPathData

The virtual path for the page if it handled by a route in the collection; otherwise, null.

GetVirtualPath(RouteCollection, ContentReference, String, ContextMode)

Returns the virtual path for the page as it is specified by the first matching route.

Declaration
[Obsolete("Use the methods in UrlResolver instead.", false)]
public static VirtualPathData GetVirtualPath(this RouteCollection routes, ContentReference contentLink, string language, ContextMode contextMode)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

ContentReference contentLink

The content reference for which to the virtual path.

System.String language

The language code that should be used when creating the virtual path.

ContextMode contextMode

Either a specific context mode or Undefined to follow the context mode for the current request.

Returns
Type Description
System.Web.Routing.VirtualPathData

The virtual path for the page if it handled by a route in the collection; otherwise, null.

GetVirtualPath(RouteCollection, ContentReference, String, ContextMode, Object)

Returns the virtual path for the page as it is specified by the first matching route.

Declaration
[Obsolete("Use the methods in UrlResolver instead.", false)]
public static VirtualPathData GetVirtualPath(this RouteCollection routes, ContentReference contentLink, string language, ContextMode contextMode, object routeValues)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

ContentReference contentLink

The content reference for which to the virtual path.

System.String language

The language code that should be used when creating the virtual path.

ContextMode contextMode

Either a specific context mode or Undefined to follow the context mode for the current request.

System.Object routeValues

The route values.

Returns
Type Description
System.Web.Routing.VirtualPathData

The virtual path for the page if it handled by a route in the collection; otherwise, null.

GetVirtualPath(RouteCollection, ContentReference, String, Boolean)

Returns the virtual path for the page as it is specified by the first matching route.

Declaration
[Obsolete("Use the methods in UrlResolver instead.", false)]
public static VirtualPathData GetVirtualPath(this RouteCollection routes, ContentReference contentLink, string language, bool forceIsInEditMode)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

ContentReference contentLink

The content reference for which to the virtual path.

System.String language

The language code that should be used when creating the virtual path.

System.Boolean forceIsInEditMode

if set to true the virtual path will be created as if it was created in edit mode.

Returns
Type Description
System.Web.Routing.VirtualPathData

The virtual path for the page if it handled by a route in the collection; otherwise, null.

GetVirtualPath(RouteCollection, ContentReference, String, Boolean, Boolean)

Returns the virtual path for the page as it is specified by the first matching route.

Declaration
[Obsolete("Use the methods in UrlResolver instead.", false)]
public static VirtualPathData GetVirtualPath(this RouteCollection routes, ContentReference contentLink, string language, bool setIdAsQueryParameter, bool forceIsInEditMode)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

ContentReference contentLink

The content reference for which to the virtual path.

System.String language

The language code that should be used when creating the virtual path.

System.Boolean setIdAsQueryParameter

if set to true the page id is set as query parameter.

System.Boolean forceIsInEditMode

if set to true the virtual path will be created as if it was created in edit mode.

Returns
Type Description
System.Web.Routing.VirtualPathData

The virtual path for the page if it handled by a route in the collection; otherwise, null.

GetVirtualPathForNonContent(RouteCollection, Object, String)

Gets the virtual path for an object that is not an IContent object but has been routed by a partial router.

Declaration
[Obsolete("Use UrlResolver.Current.GetVirtualPathForNonContent instead.")]
public static VirtualPathData GetVirtualPathForNonContent(this RouteCollection routes, object partialRoutedObject, string language)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.Object partialRoutedObject

The object instance for which a virtual path should be generated.

System.String language

The language code that should be used when creating the virtual path.

Returns
Type Description
System.Web.Routing.VirtualPathData

The virtual path for the page if it handled by a route in the collection; otherwise, null.

Remarks

For virtual path to IContent, use the GetVirtualPath method with the content's ContentReference, which also handles cases where the content is partial routed.

GetVirtualPathForPartialRouted(RouteCollection, Object, String)

Declaration
[Obsolete("Use UrlResolver.Current.GetVirtualPathForNonContent instead.")]
public static VirtualPathData GetVirtualPathForPartialRouted(this RouteCollection routes, object partialRoutedObject, string language)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes
System.Object partialRoutedObject
System.String language
Returns
Type Description
System.Web.Routing.VirtualPathData

MapAssetRoutes(RouteCollection, String, String, Object, String, String, String)

Creates and adds site media routes to the route collection. One route will be added for each media root found in the SiteDefinition.

Declaration
public static void MapAssetRoutes(this RouteCollection routes, string name, string url, object defaults, string staticSegmentPlaceHolder, string globalReplacement, string siteReplacement)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

System.String staticSegmentPlaceHolder

The static segment place holder that should be part of url if not null

System.String globalReplacement

The global replacement that will replace staticSegmentPlaceHolder for global media roots

System.String siteReplacement

The site replacement that will replace staticSegmentPlaceHolder for site media roots

MapContentAssetsRoute(RouteCollection, String, String, Object)

Creates and adds a route for content assets to the route collection.

Declaration
public static void MapContentAssetsRoute(this RouteCollection routes, string name, string url, object defaults)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

Remarks

If a page route with the same name exists, it will be overwritten.

MapContentRoute(RouteCollection, String, String, Object)

Creates and adds a content route to the route collection.

Declaration
public static ContentRoute MapContentRoute(this RouteCollection routes, string name, string url, object defaults)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

Returns
Type Description
ContentRoute

The content route that was added to the collection.

Remarks

If a content route with the same name exists, it will be overwritten.

MapContentRoute(RouteCollection, String, String, Object, MapContentRouteParameters)

Creates and adds a content route to the route collection.

Declaration
public static ContentRoute MapContentRoute(this RouteCollection routes, string name, string url, object defaults, MapContentRouteParameters parameters)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

MapContentRouteParameters parameters

Additional parameter values for the route.

Returns
Type Description
ContentRoute

The content route that was added to the collection.

Remarks

If a content route with the same name exists, it will be overwritten.

MapContentRoute(RouteCollection, String, String, Object, Func<SiteDefinition, ContentReference>)

Creates and adds a route below content root to the route collection.

Declaration
public static void MapContentRoute(this RouteCollection routes, string name, string url, object defaults, Func<SiteDefinition, ContentReference> contentRootResolver)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

System.Func<SiteDefinition, ContentReference> contentRootResolver

The content root resolver.

Remarks

If a content route with the same name exists, it will be overwritten.

MapEnterpriseRoutes(RouteCollection, String, String, Object)

Creates and adds site page routes to the route collection. One route will be added for each site instance found in the configuration.

Declaration
public static void MapEnterpriseRoutes(this RouteCollection routes, string name, string url, object defaults)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

Remarks

For each site other than the one running in this application (i.e. another site in an Enterprise setup) its SiteId will be appended to name before the route is added to the collection.

If a page route with the same name exists, it will be overwritten.

MapEnterpriseRoutes(RouteCollection, String, String, Object, Object)

Creates and adds site page routes to the route collection. One route will be added for each site instance found in the configuration.

Declaration
public static void MapEnterpriseRoutes(this RouteCollection routes, string name, string url, object defaults, object constraints)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

System.Object constraints

Constraints that a URL request must meet in order to be processed as this route.

Remarks

For each site other than the one running in this application (i.e. another site in an Enterprise setup) its SiteId will be appended to name before the route is added to the collection.

If a page route with the same name exists, it will be overwritten.

MapPageRootRoute(RouteCollection, String, String, Object)

Creates and adds a route that handles the pages outside of the start page to the route collection.

Declaration
public static void MapPageRootRoute(this RouteCollection routes, string name, string url, object defaults)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

Remarks

This registration should be last of all items for better performance. It acts for both incoming and outgoing requests.

MapPageRootRoute(RouteCollection, String, String, Object, Object)

Creates and adds a route that handles the pages outside of the start page to the route collection.

Declaration
public static void MapPageRootRoute(this RouteCollection routes, string name, string url, object defaults, object constraints)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

System.Object constraints

Constraints that a URL request must meet in order to be processed as this route.

Remarks

This registration should be last of all items for better performance. It acts for both incoming and outgoing requests.

MapSimpleAddressRoute(RouteCollection, String, String, Object)

Creates and adds a simple adress route to the route collection.

Declaration
public static void MapSimpleAddressRoute(this RouteCollection routes, string name, string url, object defaults)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

Remarks

If a page route with the same name exists, it will be overwritten.

MapSimpleAddressRoute(RouteCollection, String, String, Object, Object)

Creates and adds a simple adress route to the route collection.

Declaration
public static void MapSimpleAddressRoute(this RouteCollection routes, string name, string url, object defaults, object constraints)
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The route collection instance that this method extends.

System.String name

The name of the route.

System.String url

The URL pattern for the route.

System.Object defaults

Default values for the route parameters.

System.Object constraints

Constraints that a URL request must meet in order to be processed as this route.

Remarks

If a page route with the same name exists, it will be overwritten.

RegisterPartialRouter<TContent, TRoutedData>(RouteCollection, IPartialRouter<TContent, TRoutedData>)

Registers an instance of IPartialRouter<TContent, TRoutedData> that extends routing for IContent instances.

Declaration
public static RouteCollection RegisterPartialRouter<TContent, TRoutedData>(this RouteCollection routes, IPartialRouter<TContent, TRoutedData> partialRouter)
    where TContent : class, IContent where TRoutedData : class
Parameters
Type Name Description
System.Web.Routing.RouteCollection routes

The routes

IPartialRouter<TContent, TRoutedData> partialRouter

The partial router that extends content routing.

Returns
Type Description
System.Web.Routing.RouteCollection

The routecollection

Type Parameters
Name Description
TContent

The type of IContent for which incoming routing can be extended.

TRoutedData

The type for which outgoing routing is extended to.

ResolveBasePath(RequestContext, RouteValueDictionary)

The implementation resolves root dir by comparing the SiteDefinition for the routed content with Current if they are same the root dir vill be ApplicationVirtualPath. If they differ (typically when cross linking in an enterprise setup) then RootDir will be resolved as SiteUrl to the site linking to.

Declaration
[Obsolete("Use BasePathResolver class instead")]
public static string ResolveBasePath(RequestContext request, RouteValueDictionary routeValues)
Parameters
Type Name Description
System.Web.Routing.RequestContext request

The request.

System.Web.Routing.RouteValueDictionary routeValues

The route values.

Returns
Type Description
System.String