U4-9551 - URL collision with custom IUrlProvider and common URL prefixes

Created by Matt Painter 20 Feb 2017, 22:48:20 Updated by Stephan 01 Mar 2017, 14:11:23

Tags: Unscheduled

Relates to: U4-9430

We have extended Umbraco to provide JSON representations of pages. These are retrievable via a custom endpoint mounted at {{/api/data/}}.

We have a corresponding {{IUrlProvider}} which constructs these URLs. For example, for a page with title 'Some Child' which is a child of a page with title 'Some Parent', the relative URL returned will be {{/api/data/someparent/somechild}}.

After upgrading from 7.5.4 to 7.5.9, this is causing the link to document on the Properties tab to display the following error instead of the custom URL:

{{This document is published but its url would collide with content (error)}}

Experimenting with my provider shows that the common {{/api/data}} prefix seems to trigger this error. It appears that the conflicting route check is assuming that all segments of the URL provider are provided by Umbraco-managed data as opposed to by custom controllers.

Comments

Stephan 22 Feb 2017, 09:37:23

What happens is: the backoffice uses the IUrlProvider mechanism to generate the url for a content item, then tries to route this url back, to see whether it matches the original content item, or ''another'' content item, in which case it raises a warning because it thinks that you have just generated a url that will in fact not route to the original content item.

So in your case, content item "SomeChild" produces url "/api/data/someparent/somechild" due to your custom IUrlProvider, but when we try to route that url back, it fails (cannot find content matching "/api/data/someparent/somechild"), thus the error message.

That's normal in your case, because I assume you have some controller / custom end point dealing with the url. But the error message is misleading. Problem is, in theory a url ''should'' route back to the content item...

The collision detection mechanism has been improved in 7.5.9 and now it detects your situation, whereas with 7.5.4 I guess it went unnoticed.

One way to get rid of the error would be to write an IContentFinder that would map "/api/data/path/to/whatever" to content item "Whatever" (has to be the same content item, not just a random one) so that Umbraco is happy. That would work with 7.5.9. But it's a bit cumbersome.

Trying to think about a better way for future versions...

Am I making sense?


Matt Painter 22 Feb 2017, 22:20:27

Yes, that makes good sense. Thanks Stephan. I'll give that a go now.


Matt Painter 22 Feb 2017, 23:21:49

I can confirm that that approach works well.


Stephan 01 Mar 2017, 14:10:55

Great


Priority: Normal

Type: Bug

State: Closed

Assignee:

Difficulty: Normal

Category: Extensibility

Backwards Compatible: True

Fix Submitted:

Affected versions: 7.5.9

Due in version:

Sprint: Sprint 53

Story Points:

Cycle: