Class UrlResolver
Class that routes an url to the corresponding IContent instance or vice versa.
Inherited Members
Namespace: EPiServer.Web.Routing
Assembly: EPiServer.dll
Version: 8.11.0Syntax
public abstract class UrlResolver
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
ConvertToPermanent(UrlBuilder, IContent)
Converts an url for content
to permanent format.
Declaration
protected abstract bool ConvertToPermanent(UrlBuilder url, IContent content)
Parameters
Type | Name | Description |
---|---|---|
UrlBuilder | url | The url to convert |
IContent | content | The content to create permanent format for. |
Returns
Type | Description |
---|---|
System.Boolean | true if the url was converted else false. |
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 |
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 |
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 |
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 |
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 |
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 virtual 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 |
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 |
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).
GetVirtualPathForPartialRouted(Object, String)
Declaration
[Obsolete("Use GetVirtualPathForNonContent")]
public virtual VirtualPathData GetVirtualPathForPartialRouted(object partialRoutedObject, string language)
Parameters
Type | Name | Description |
---|---|---|
System.Object | partialRoutedObject | |
System.String | language |
Returns
Type | Description |
---|---|
System.Web.Routing.VirtualPathData |
GetVirtualPathInternal(ContentReference, String, VirtualPathArguments)
Tries to get the URL for a content and mode and returns a System.Web.Routing.VirtualPathData that contains the routing information.
Declaration
protected abstract VirtualPathData GetVirtualPathInternal(ContentReference contentLink, string language, VirtualPathArguments arguments)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | contentLink | |
System.String | language | |
VirtualPathArguments | arguments |
Returns
Type | Description |
---|---|
System.Web.Routing.VirtualPathData | A virtual path or |
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 |
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. |