Class UrlProvider
Provides URLs.
Inheritance
Namespace: Umbraco.Web.Routing
Assembly: Umbraco.Web.dll
Syntax
public class UrlProvider
Constructors
View SourceUrlProvider(UmbracoContext, IEnumerable<IUrlProvider>, IEnumerable<IMediaUrlProvider>, IVariationContextAccessor, UrlMode)
Initializes a new instance of the UrlProvider class with an Umbraco context and a list of URL providers.
Declaration
public UrlProvider(UmbracoContext umbracoContext, IEnumerable<IUrlProvider> urlProviders, IEnumerable<IMediaUrlProvider> mediaUrlProviders, IVariationContextAccessor variationContextAccessor, UrlMode mode = UrlMode.Auto)
Parameters
Type | Name | Description |
---|---|---|
UmbracoContext | umbracoContext | The Umbraco context. |
System.Collections.Generic.IEnumerable<IUrlProvider> | urlProviders | The list of URL providers. |
System.Collections.Generic.IEnumerable<IMediaUrlProvider> | mediaUrlProviders | The list of media URL providers |
IVariationContextAccessor | variationContextAccessor | The current variation accessor. |
UrlMode | mode | An optional provider mode. |
UrlProvider(UmbracoContext, IWebRoutingSection, IEnumerable<IUrlProvider>, IEnumerable<IMediaUrlProvider>, IVariationContextAccessor)
Initializes a new instance of the UrlProvider class with an Umbraco context and a list of URL providers.
Declaration
public UrlProvider(UmbracoContext umbracoContext, IWebRoutingSection routingSettings, IEnumerable<IUrlProvider> urlProviders, IEnumerable<IMediaUrlProvider> mediaUrlProviders, IVariationContextAccessor variationContextAccessor)
Parameters
Type | Name | Description |
---|---|---|
UmbracoContext | umbracoContext | The Umbraco context. |
IWebRoutingSection | routingSettings | Routing settings. |
System.Collections.Generic.IEnumerable<IUrlProvider> | urlProviders | The list of URL providers. |
System.Collections.Generic.IEnumerable<IMediaUrlProvider> | 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, 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 |
---|---|---|
System.Guid | id | |
UrlMode | mode | |
System.String | culture | |
System.String | propertyAlias | |
System.Uri | current |
Returns
Type | Description |
---|---|
System.String |
GetMediaUrl(IPublishedContent, UrlMode, String, String, 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.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 |
---|---|
System.Collections.Generic.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. |
System.Uri | current | The current absolute URL. |
Returns
Type | Description |
---|---|
System.Collections.Generic.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, 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 |
---|---|---|
System.Guid | id | The published content identifier. |
UrlMode | mode | The URL mode. |
System.String | culture | A culture. |
System.Uri | current | The current absolute URL. |
Returns
Type | Description |
---|---|
System.String | The URL for the published content. |
GetUrl(Int32, UrlMode, String, 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.Uri | current | The current absolute URL. |
Returns
Type | Description |
---|---|
System.String | The URL for the published content. |
GetUrl(IPublishedContent, UrlMode, String, 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.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 "#".