Class UrlProvider
Provides URLs.
Inheritance
Namespace: Umbraco.Cms.Core.Routing
Assembly: Umbraco.Core.dll
Syntax
public class UrlProvider : IPublishedUrlProvider
Constructors
View SourceUrlProvider(IUmbracoContextAccessor, IOptions<WebRoutingSettings>, UrlProviderCollection, MediaUrlProviderCollection, IVariationContextAccessor)
Initializes a new instance of the UrlProvider class with an Umbraco context and a list of URL providers.
Declaration
public UrlProvider(IUmbracoContextAccessor umbracoContextAccessor, IOptions<WebRoutingSettings> routingSettings, UrlProviderCollection urlProviders, MediaUrlProviderCollection mediaUrlProviders, IVariationContextAccessor variationContextAccessor)
Parameters
Type | Name | Description |
---|---|---|
IUmbracoContextAccessor | umbracoContextAccessor | The Umbraco context accessor. |
IOptions<WebRoutingSettings> | routingSettings | Routing settings. |
UrlProviderCollection | urlProviders | The list of URL providers. |
MediaUrlProviderCollection | mediaUrlProviders | The list of media URL providers. |
IVariationContextAccessor | variationContextAccessor | The current variation accessor. |
Properties
View SourceMode
Gets or sets the provider URL mode.
Declaration
public UrlMode Mode { get; set; }
Property Value
Type | Description |
---|---|
UrlMode |
Methods
View SourceGetMediaUrl(Guid, UrlMode, String, String, Nullable<Uri>)
Gets the URL of a media item.
Declaration
public string GetMediaUrl(Guid id, UrlMode mode = UrlMode.Default, string culture = null, string propertyAlias = "umbracoFile", Uri? current = null)
Parameters
Type | Name | Description |
---|---|---|
Guid | id | |
UrlMode | mode | |
System.String | culture | |
System.String | propertyAlias | |
System.Nullable<Uri> | current |
Returns
Type | Description |
---|---|
System.String |
GetMediaUrl(IPublishedContent, UrlMode, String, String, Nullable<Uri>)
Gets the URL of a media item.
Declaration
public string GetMediaUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string culture = null, string propertyAlias = "umbracoFile", Uri? current = null)
Parameters
Type | Name | Description |
---|---|---|
IPublishedContent | content | The published content. |
UrlMode | mode | The URL mode. |
System.String | culture | The variation language. |
System.String | propertyAlias | The property alias to resolve the URL from. |
System.Nullable<Uri> | current | The current absolute URL. |
Returns
Type | Description |
---|---|
System.String | The URL for the media. |
Remarks
The URL is absolute or relative depending on mode
and on current
.
If the media is multi-lingual, gets the URL for the specified culture or, when no culture is specified, the current culture.
If the provider is unable to provide a URL, it returns System.String.Empty.
GetOtherUrls(Int32)
Gets the other URLs of a published content.
Declaration
public IEnumerable<UrlInfo> GetOtherUrls(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | The published content id. |
Returns
Type | Description |
---|---|
IEnumerable<UrlInfo> | The other URLs for the published content. |
Remarks
Other URLs are those that GetUrl
would not return in the current context, but would be valid
URLs for the node in other contexts (different domain for current request, umbracoUrlAlias...).
The results depend on the current URL.
GetOtherUrls(Int32, Uri)
Gets the other URLs of a published content.
Declaration
public IEnumerable<UrlInfo> GetOtherUrls(int id, Uri current)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | The published content id. |
Uri | current | The current absolute URL. |
Returns
Type | Description |
---|---|
IEnumerable<UrlInfo> | The other URLs for the published content. |
Remarks
Other URLs are those that GetUrl
would not return in the current context, but would be valid
URLs for the node in other contexts (different domain for current request, umbracoUrlAlias...).
GetUrl(Guid, UrlMode, String, Nullable<Uri>)
Gets the URL of a published content.
Declaration
public string GetUrl(Guid id, UrlMode mode = UrlMode.Default, string culture = null, Uri? current = null)
Parameters
Type | Name | Description |
---|---|---|
Guid | id | The published content identifier. |
UrlMode | mode | The URL mode. |
System.String | culture | A culture. |
System.Nullable<Uri> | current | The current absolute URL. |
Returns
Type | Description |
---|---|
System.String | The URL for the published content. |
GetUrl(Int32, UrlMode, String, Nullable<Uri>)
Gets the URL of a published content.
Declaration
public string GetUrl(int id, UrlMode mode = UrlMode.Default, string culture = null, Uri? current = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | The published content identifier. |
UrlMode | mode | The URL mode. |
System.String | culture | A culture. |
System.Nullable<Uri> | current | The current absolute URL. |
Returns
Type | Description |
---|---|
System.String | The URL for the published content. |
GetUrl(IPublishedContent, UrlMode, String, Nullable<Uri>)
Gets the URL of a published content.
Declaration
public string GetUrl(IPublishedContent content, UrlMode mode = UrlMode.Default, string culture = null, Uri? current = null)
Parameters
Type | Name | Description |
---|---|---|
IPublishedContent | content | The published content. |
UrlMode | mode | The URL mode. |
System.String | culture | A culture. |
System.Nullable<Uri> | current | The current absolute URL. |
Returns
Type | Description |
---|---|
System.String | The URL for the published content. |
Remarks
The URL is absolute or relative depending on mode
and on current
.
If the published content is multi-lingual, gets the URL for the specified culture or, when no culture is specified, the current culture.
If the provider is unable to provide a URL, it returns "#".
GetUrlFromRoute(Int32, String, String)
Declaration
public string GetUrlFromRoute(int id, string route, string culture)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | |
System.String | route | |
System.String | culture |
Returns
Type | Description |
---|---|
System.String |