Interface IDocumentUrlAliasService
Defines operations for handling document URL aliases (umbracoUrlAlias property).
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
Syntax
public interface IDocumentUrlAliasService
Properties
View SourceIsInitialized
Gets a value indicating whether the service has been initialized and may persist aliases.
Declaration
bool IsInitialized { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
False while the application is upgrading, when the alias table may not exist yet.
Methods
View SourceCreateOrUpdateAliasesAsync(Guid)
Creates or updates the aliases for a single document.
Declaration
Task CreateOrUpdateAliasesAsync(Guid documentKey)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | documentKey | The document key. |
Returns
| Type | Description |
|---|---|
| Task |
CreateOrUpdateAliasesWithDescendantsAsync(Guid)
Creates or updates the aliases for a document and its descendants.
Declaration
Task CreateOrUpdateAliasesWithDescendantsAsync(Guid documentKey)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | documentKey | The document key. |
Returns
| Type | Description |
|---|---|
| Task |
DeleteAliasesFromCacheAsync(IEnumerable<Guid>)
Deletes all aliases from the cache for a collection of document keys.
Declaration
Task DeleteAliasesFromCacheAsync(IEnumerable<Guid> documentKeys)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<Guid> | documentKeys | The collection of document keys. |
Returns
| Type | Description |
|---|---|
| Task |
GetAliasesAsync(Guid, string?)
Gets all URL aliases for a given document.
Declaration
Task<IEnumerable<string>> GetAliasesAsync(Guid documentKey, string? culture)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | documentKey | The document key. |
| string | culture | The culture code (null for default language). |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<string>> | All aliases for the document in the specified culture, or empty if none found. |
GetDocumentKeysByAliasAsync(string, string?)
Gets all document keys that match a given URL alias.
Declaration
Task<IEnumerable<Guid>> GetDocumentKeysByAliasAsync(string alias, string? culture)
Parameters
| Type | Name | Description |
|---|---|---|
| string | alias | The URL alias (normalized: lowercase, no leading slash). |
| string | culture | The culture code (null for invariant). |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<Guid>> | All document keys that have the specified alias, or empty if none found. |
HasAny()
Checks whether any aliases are cached.
Declaration
bool HasAny()
Returns
| Type | Description |
|---|---|
| bool |
|
InitAsync(bool, CancellationToken)
Initializes the service and ensures the alias cache is populated from the database.
Declaration
Task InitAsync(bool forceEmpty, CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | forceEmpty | Forces an early return when we know there are no aliases (i.e. on install). |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
PersistAliasesAsync(IContent)
Persists the aliases of a document from the document itself, taking the locks that order the write against saves and against RebuildAllAliasesAsync().
Declaration
Task PersistAliasesAsync(IContent document)
Parameters
| Type | Name | Description |
|---|---|---|
| IContent | document | The document whose aliases to persist. |
Returns
| Type | Description |
|---|---|
| Task | A task that completes when the aliases are persisted. |
PersistAliasesAsync(IContent, bool)
Persists the aliases of a document from the document itself.
Declaration
Task PersistAliasesAsync(IContent document, bool contentTreeWriteLockHeld)
Parameters
| Type | Name | Description |
|---|---|---|
| IContent | document | The document whose aliases to persist. |
| bool | contentTreeWriteLockHeld | True only when the caller holds the content tree write lock, as the transaction that persists
|
Returns
| Type | Description |
|---|---|
| Task | A task that completes when the aliases are persisted. |
Remarks
The CMS calls this from the document repository's refresh notification, inside the transaction that persists
document. Only a change to the document's published state or trashed state can change its
aliases, so any other save is a no-op. Implementations must work from document itself:
inside the content transaction the repository caches still hold the document as it was before the save, so
loading it by key would persist the previous aliases. The default implementation only keeps implementations
written before this member compiling; it is not a correct implementation of the contract.
RebuildAllAliasesAsync()
Rebuilds all URL aliases from the database.
Declaration
Task RebuildAllAliasesAsync()
Returns
| Type | Description |
|---|---|
| Task |
Remarks
This method clears the existing alias cache and database records, then rebuilds from the umbracoUrlAlias property values on all documents.
UpdateAliasCacheAsync(Guid)
Updates the in-memory alias cache for a single document without writing to the database.
Declaration
Task UpdateAliasCacheAsync(Guid documentKey)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | documentKey | The document key. |
Returns
| Type | Description |
|---|---|
| Task |
UpdateAliasCacheWithDescendantsAsync(Guid)
Updates the in-memory alias cache for a document and its descendants without writing to the database.
Declaration
Task UpdateAliasCacheWithDescendantsAsync(Guid documentKey)
Parameters
| Type | Name | Description |
|---|---|---|
| Guid | documentKey | The document key. |
Returns
| Type | Description |
|---|---|
| Task |