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

Class UrlResolver

Class that routes an url to the corresponding IContent instance or vice versa.

Inheritance
System.Object
UrlResolver
Implements
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.Cms.AspNet.dll
Version: 11.20.7
Syntax
public abstract class UrlResolver : IUrlResolver

Constructors

UrlResolver()

Declaration
protected UrlResolver()

Properties

Current

Gets the current instance from the ServiceLocator.

Declaration
public static UrlResolver Current { get; }
Property Value
Type Description
UrlResolver

The current instance.

RoutedQueryParameters

Contains a list of query parameters that are passed on to routing.

Declaration
public static IEnumerable<string> RoutedQueryParameters { get; }
Property Value
Type Description
System.Collections.Generic.IEnumerable<System.String>

Methods

GetPermanent(String, Boolean)

Tries to resolve the URL to a permanent URL. If this does not possible it returns the original URL.

Declaration
public virtual string GetPermanent(string url, bool enableFallback)
Parameters
Type Name Description
System.String url

The URL.

System.Boolean enableFallback

If set to true returns the given URL if the conversion fails.

Returns
Type Description
System.String

Either a permanent URL or the given URL/String.Empty depending on if fallback is enabled.

GetUrl(ContentReference)

Gets the URL for a IContent instance that is given by reference contentLink.

Declaration
public virtual string GetUrl(ContentReference contentLink)
Parameters
Type Name Description
ContentReference contentLink

The content link.

Returns
Type Description
System.String

A string representing the URL or null if it was not possible to create a route to the content (for example the content does not exist or has no template)

Remarks

This method will get the URL for the language given by PreferredCulture.

The returned url can be relative or absolute (including host) depending on if the contentLink is on current site and current request matches host that matches content and language. Overload GetVirtualPath can be used to always get relative virtual path.

GetUrl(ContentReference, String)

Gets the URL for a IContent instance that is given by reference contentLink

Declaration
public virtual string GetUrl(ContentReference contentLink, string language)
Parameters
Type Name Description
ContentReference contentLink

The content.

System.String language

The language.

Returns
Type Description
System.String

A string representing the URL or null if it was not possible to create a route to the content (for example the content does not exist or has no template)

Remarks

The returned url can be relative or absolute (including host) depending on if the contentLink is on current site and current request matches host that matches content and language. Overload GetVirtualPath can be used to always get relative virtual path.

GetUrl(ContentReference, String, VirtualPathArguments)

Gets the URL for a IContent instance that is given by argument virtualPathArguments.

Declaration
public virtual string GetUrl(ContentReference contentLink, string language, VirtualPathArguments virtualPathArguments)
Parameters
Type Name Description
ContentReference contentLink

The content link.

System.String language

The language.

VirtualPathArguments virtualPathArguments

The virtual path arguments.

Returns
Type Description
System.String

A string representing the URL or null if it was not possible to create a route to the content (for example the content does not exist or has no template)

Remarks

The returned url can be relative or absolute (including host) depending on if the contentLink is on current site and current request matches host that matches content and language. Overload GetVirtualPath can be used to always get relative virtual path.

GetUrl(IContent)

Gets the URL for the content instance.

Declaration
public virtual string GetUrl(IContent content)
Parameters
Type Name Description
IContent content

The content instance.

Returns
Type Description
System.String

A string representing the URL or null if it was not possible to create a route to the content (for example the content does not exist or has no template)

Remarks

The returned url can be relative or absolute (including host) depending on if the content is on current site and current request matches host that matches content and language. Overload GetVirtualPath can be used to always get relative virtual path.

GetUrl(UrlBuilder, ContextMode)

Resolves the URL for an item from an URL with internal format.

Declaration
public virtual string GetUrl(UrlBuilder urlBuilderWithInternalUrl, ContextMode mode)
Parameters
Type Name Description
UrlBuilder urlBuilderWithInternalUrl

The URL with a internal format.

ContextMode mode

The ContextMode that determines the format of the link.

Returns
Type Description
System.String

A URL in string representation.

Remarks

The returned url can be relative or absolute (including host) depending on if the urlBuilderWithInternalUrl is on current site and current request matches host that matches content and language. Overload GetVirtualPath can be used to always get relative virtual path.

GetUrl(UrlBuilder, VirtualPathArguments)

Resolves the URL for an item from an URL with internal format.

Declaration
public abstract string GetUrl(UrlBuilder urlBuilderWithInternalUrl, VirtualPathArguments arguments)
Parameters
Type Name Description
UrlBuilder urlBuilderWithInternalUrl

The URL with a internal format.

VirtualPathArguments arguments

The VirtualPathArguments that determines the format of the link.

Returns
Type Description
System.String

A URL in string representation.

Remarks

The returned url can be relative or absolute (including host) depending on if the urlBuilderWithInternalUrl is on current site and current request matches host that matches content and language. Overload GetVirtualPath can be used to always get relative virtual path.

GetUrl(String)

Resolves the URL for an item from an URL with internal format.

Declaration
public virtual string GetUrl(string internalUrl)
Parameters
Type Name Description
System.String internalUrl

The URL with a internal format.

Returns
Type Description
System.String

A URL in string representation.

Remarks

The returned url can be relative or absolute (including host) depending on if the internalUrl is on current site and current request matches host that matches content and language. Overload GetVirtualPath can be used to always get relative virtual path.

GetVirtualPath(ContentReference)

Gets the url for a IContent instance that is given by reference contentLink

Declaration
public virtual VirtualPathData GetVirtualPath(ContentReference contentLink)
Parameters
Type Name Description
ContentReference contentLink

The content.

Returns
Type Description
System.Web.Routing.VirtualPathData
Remarks

This method will get the url for the language given by PreferredCulture.

The returned value System.Web.Routing.VirtualPathData.VirtualPath is always a relative path (host and application is not included), call extension method GetUrl on VirtualPathData to get an absolute path (there is an overload that can be used if authority part should not be included).

GetVirtualPath(ContentReference, String)

Gets the url for a IContent instance that is given by reference contentLink

Declaration
public virtual VirtualPathData GetVirtualPath(ContentReference contentLink, string language)
Parameters
Type Name Description
ContentReference contentLink

The content.

System.String language

The language.

Returns
Type Description
System.Web.Routing.VirtualPathData
Remarks

The returned value System.Web.Routing.VirtualPathData.VirtualPath is always a relative path (host and application is not included), call extension method GetUrl on VirtualPathData to get an absolute path (there is an overload that can be used if authority part should not be included).

GetVirtualPath(ContentReference, String, VirtualPathArguments)

Gets the url for a IContent instance that is given by reference virtualPathArguments

Declaration
public abstract VirtualPathData GetVirtualPath(ContentReference contentLink, string language, VirtualPathArguments virtualPathArguments)
Parameters
Type Name Description
ContentReference contentLink

The content link.

System.String language

The language.

VirtualPathArguments virtualPathArguments

The virtual path arguments.

Returns
Type Description
System.Web.Routing.VirtualPathData

A virtual path or null if it was not possible to create a route to the content (for example the content does not exist or has no template)

Remarks

The returned value System.Web.Routing.VirtualPathData.VirtualPath is always a relative path (host and application is not included), call extension method GetUrl on VirtualPathData to get an absolute path (there is an overload that can be used if authority part should not be included).

GetVirtualPath(ContentReference, String, RouteValueDictionary, RequestContext)

Gets the url for a IContent instance that is given by reference contentLink

Declaration
public virtual VirtualPathData GetVirtualPath(ContentReference contentLink, string language, RouteValueDictionary routeValues, RequestContext requestContext)
Parameters
Type Name Description
ContentReference contentLink

The content.

System.String language

The language.

System.Web.Routing.RouteValueDictionary routeValues

The route values.

System.Web.Routing.RequestContext requestContext

The request context.

Returns
Type Description
System.Web.Routing.VirtualPathData

A virtual path or null if it was not possible to create a route to the content (for example the content does not exist or has no template)

Remarks

The returned value System.Web.Routing.VirtualPathData.VirtualPath is always a relative path (host and application is not included), call extension method GetUrl on VirtualPathData to get an absolute path (there is an overload that can be used if authority part should not be included).

GetVirtualPath(IContent)

Gets the url for the content instance.

Declaration
public virtual VirtualPathData GetVirtualPath(IContent content)
Parameters
Type Name Description
IContent content

The content instance.

Returns
Type Description
System.Web.Routing.VirtualPathData
Remarks

The returned value System.Web.Routing.VirtualPathData.VirtualPath is always a relative path (host and application is not included), call extension method GetUrl on VirtualPathData to get an absolute path (there is an overload that can be used if authority part should not be included).

GetVirtualPathForNonContent(Object, String, VirtualPathArguments)

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

Declaration
public abstract VirtualPathData GetVirtualPathForNonContent(object partialRoutedObject, string language, VirtualPathArguments virtualPathArguments)
Parameters
Type Name Description
System.Object partialRoutedObject

The partial routed object.

System.String language

The language.

VirtualPathArguments virtualPathArguments

The virtual path arguments.

Returns
Type Description
System.Web.Routing.VirtualPathData
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.

The returned value System.Web.Routing.VirtualPathData.VirtualPath is always a relative path (host and application is not included), call extension method GetUrl on VirtualPathData to get an absolute path (there is an overload that can be used if authority part should not be included).

Route(UrlBuilder)

Routes the URL to the corresponding IContent instance.

Declaration
public virtual IContent Route(UrlBuilder urlBuilder)
Parameters
Type Name Description
UrlBuilder urlBuilder

The URL builder.

Returns
Type Description
IContent

Route(UrlBuilder, ContextMode)

Routes the URL to the corresponding IContent instance.

Declaration
public abstract IContent Route(UrlBuilder urlBuilder, ContextMode contextMode)
Parameters
Type Name Description
UrlBuilder urlBuilder

The URL builder.

ContextMode contextMode

The ContextMode

Returns
Type Description
IContent

Route(String, RouteArguments)

Routes the URL to the corresponding ContentRouteData instance.

Declaration
public virtual ContentRouteData Route(string url, RouteArguments routeArguments)
Parameters
Type Name Description
System.String url

The url.

RouteArguments routeArguments

The RouteArguments

Returns
Type Description
ContentRouteData

TryToPermanent(String, out String)

Tries to convert a URL with either a public, preview or permanent format to a permanent URL.

Declaration
public abstract bool TryToPermanent(string url, out string permanentUrl)
Parameters
Type Name Description
System.String url

The URL.

System.String permanentUrl

The permanent URL.

Returns
Type Description
System.Boolean

True if the conversion succeded, otherwise; false.

Explicit Interface Implementations

IUrlResolver.GetUrl(ContentReference, String, UrlResolverArguments)

Gets the URL for a IContent instance that is given by argument urlResolverArguments.

Declaration
string IUrlResolver.GetUrl(ContentReference contentLink, string language, UrlResolverArguments urlResolverArguments)
Parameters
Type Name Description
ContentReference contentLink

The content link.

System.String language

The language.

UrlResolverArguments urlResolverArguments

The arguments used at url resolving

Returns
Type Description
System.String

A string representing the URL or null if it was not possible to create a route to the content

Remarks

The returned url can be relative or absolute (including host) depending on if the contentLink is on current site and current request matches host that matches content and language.

IUrlResolver.GetUrl(UrlBuilder, UrlResolverArguments)

Resolves the URL for an item from an URL with internal format.

Declaration
string IUrlResolver.GetUrl(UrlBuilder urlBuilderWithInternalUrl, UrlResolverArguments arguments)
Parameters
Type Name Description
UrlBuilder urlBuilderWithInternalUrl

The URL with a internal format.

UrlResolverArguments arguments

The UrlResolverArguments that determines the format of the link.

Returns
Type Description
System.String

A URL in string representation.

Remarks

The returned url can be relative or absolute (including host) depending on if the urlBuilderWithInternalUrl is on current site and current request matches host that matches content and language.

Implements

Extension Methods