Routing: Added method to IDocumentUrlService for retrieving document key from URI (closes #20666)#20673
Merged
nikolajlauridsen merged 1 commit intov17/devfrom Oct 29, 2025
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new GetDocumentKeyByUri method to the IDocumentUrlService interface to enable retrieval of document keys from URIs when domains are involved. This addresses the limitation where GetDocumentKeyByRoute alone was insufficient when working with domains.
Key Changes:
- Added
GetDocumentKeyByUrimethod that parses domains from URIs and delegates toGetDocumentKeyByRoute - Updated constructor to inject
WebRoutingSettingsandIDefaultCultureAccessordependencies needed for domain resolution - Added comprehensive integration tests covering both domain and non-domain scenarios
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Umbraco.Core/Services/IDocumentUrlService.cs | Adds GetDocumentKeyByUri method signature with default implementation |
| src/Umbraco.Core/Services/DocumentUrlService.cs | Implements GetDocumentKeyByUri method and updates constructor with required dependencies |
| src/Umbraco.Core/Routing/DomainUtilities.cs | Removes unused imports |
| tests/Umbraco.Tests.Integration/Umbraco.Core/Services/DocumentUrlServiceTests.cs | Adds integration tests for the new method covering domain and non-domain scenarios |
| tests/Umbraco.Tests.Common/Builders/TemplateBuilder.cs | Makes template name parameter configurable |
tests/Umbraco.Tests.Integration/Umbraco.Core/Services/DocumentUrlServiceTests.cs
Show resolved
Hide resolved
tests/Umbraco.Tests.Integration/Umbraco.Core/Services/DocumentUrlServiceTests.cs
Show resolved
Hide resolved
nikolajlauridsen
approved these changes
Oct 29, 2025
Contributor
nikolajlauridsen
left a comment
There was a problem hiding this comment.
Looks good, tests good 👍
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Addresses: #20666
Description
This PR looks to provide a solution to the concern raised in the linked issue that it's not so easy with the
IDocumentUrlServiceto get a document's key from it's path when domains are involved.See the discussion #20666 (comment) and #20666 (comment) for why that's currently the case and a suggestion to resolve, which is what I've done in this PR.
IDocumentUrlServicenow has aGetDocumentKeyByUri(to go with the existingGetDocumentKeyByRoute) that can be called providing aUri. The domain will be parsed as is done during routing to then be able to delegate toGetDocumentKeyByRoute.Testing
The following code for a document with or without domains associated should now successfully retrieve the document's key.
Integration tests have also been added to verify the functionality.