Class DocumentUrlAliasService
Implements IDocumentUrlAliasService operations for handling document URL aliases.
Inheritance
Namespace: Umbraco.Cms.Core.Services
Assembly: Umbraco.Core.dll
Syntax
public class DocumentUrlAliasService : IDocumentUrlAliasService
Constructors
View SourceDocumentUrlAliasService(ILogger<DocumentUrlAliasService>, IDocumentUrlAliasRepository, ICoreScopeProvider, ILanguageService, IKeyValueService, IContentService, IDocumentNavigationQueryService)
Initializes a new instance of the DocumentUrlAliasService class.
Declaration
public DocumentUrlAliasService(ILogger<DocumentUrlAliasService> logger, IDocumentUrlAliasRepository documentUrlAliasRepository, ICoreScopeProvider coreScopeProvider, ILanguageService languageService, IKeyValueService keyValueService, IContentService contentService, IDocumentNavigationQueryService documentNavigationQueryService)
Parameters
| Type | Name | Description |
|---|---|---|
| ILogger<DocumentUrlAliasService> | logger | |
| IDocumentUrlAliasRepository | documentUrlAliasRepository | |
| ICoreScopeProvider | coreScopeProvider | |
| ILanguageService | languageService | |
| IKeyValueService | keyValueService | |
| IContentService | contentService | |
| IDocumentNavigationQueryService | documentNavigationQueryService |
Fields
View SourceRebuildKey
Represents the key used to identify the URL alias generation rebuild operation.
Declaration
public const string RebuildKey = "UmbracoUrlAliasGeneration"
Field Value
| Type | Description |
|---|---|
| string |
Methods
View SourceCreateOrUpdateAliasesAsync(Guid)
Creates or updates the aliases for a single document.
Declaration
public 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
public 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
public 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
public 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
public 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
public bool HasAny()
Returns
| Type | Description |
|---|---|
| bool |
|
InitAsync(bool, CancellationToken)
Initializes the service and ensures the alias cache is populated from the database.
Declaration
public 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 |
RebuildAllAliasesAsync()
Rebuilds all URL aliases from the database.
Declaration
public 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.