Class UrlResolver
Class that routes an url to the corresponding IContent instance or vice versa.
Inheritance
Implements
Namespace: EPiServer.Web.Routing
Assembly: EPiServer.Cms.AspNetCore.Templating.dll
Version: 12.0.3Syntax
public abstract class UrlResolver : Object, 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 |
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 virtual 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.
GetUrlCore(ContentReference, String, UrlResolverArguments)
The GetUrl(ContentReference, String, UrlResolverArguments) definition tbat should be implemented
Declaration
protected abstract string GetUrlCore(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 |
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.
GetUrlCore(UrlBuilder, UrlResolverArguments)
The GetUrl(UrlBuilder, UrlResolverArguments) definition tbat should be implemented
Declaration
protected abstract string GetUrlCore(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 or the passed in string if the url was not an internal content format. |
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.
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 |
---|---|
Microsoft.AspNetCore.Routing.VirtualPathData |
Remarks
This method will get the url for the language given by PreferredCulture.
The returned value Microsoft.AspNetCore.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 |
---|---|
Microsoft.AspNetCore.Routing.VirtualPathData |
Remarks
The returned value Microsoft.AspNetCore.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 |
---|---|
Microsoft.AspNetCore.Routing.VirtualPathData | A virtual path or |
Remarks
The returned value Microsoft.AspNetCore.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)
Gets the url for a IContent instance that is given by reference contentLink
Declaration
public virtual VirtualPathData GetVirtualPath(ContentReference contentLink, string language, RouteValueDictionary routeValues)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | contentLink | The content. |
System.String | language | The language. |
Microsoft.AspNetCore.Routing.RouteValueDictionary | routeValues | The route values. |
Returns
Type | Description |
---|---|
Microsoft.AspNetCore.Routing.VirtualPathData | A virtual path or |
Remarks
The returned value Microsoft.AspNetCore.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 |
---|---|
Microsoft.AspNetCore.Routing.VirtualPathData |
Remarks
The returned value Microsoft.AspNetCore.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 |
---|---|
Microsoft.AspNetCore.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 Microsoft.AspNetCore.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 virtual IContent Route(UrlBuilder urlBuilder, ContextMode contextMode)
Parameters
Type | Name | Description |
---|---|---|
UrlBuilder | urlBuilder | The URL builder. |
ContextMode | contextMode | The ContextMode |
Returns
Type | Description |
---|---|
IContent |
Route(UrlBuilder, RouteArguments)
Routes the URL to the corresponding ContentRouteData instance.
Declaration
public abstract ContentRouteData Route(UrlBuilder url, RouteArguments routeArguments)
Parameters
Type | Name | Description |
---|---|---|
UrlBuilder | 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)
Declaration
string IUrlResolver.GetUrl(ContentReference contentLink, string language, UrlResolverArguments urlResolverArguments)
Parameters
Type | Name | Description |
---|---|---|
ContentReference | contentLink | |
System.String | language | |
UrlResolverArguments | urlResolverArguments |
Returns
Type | Description |
---|---|
System.String |
IUrlResolver.GetUrl(UrlBuilder, UrlResolverArguments)
Declaration
string IUrlResolver.GetUrl(UrlBuilder urlBuilderWithInternalUrl, UrlResolverArguments arguments)
Parameters
Type | Name | Description |
---|---|---|
UrlBuilder | urlBuilderWithInternalUrl | |
UrlResolverArguments | arguments |
Returns
Type | Description |
---|---|
System.String |