patrickdemooij9 / SeoToolkit.Umbraco

SeoToolkit is a SEO package for Umbraco 9, 10, 11, 12 & 13. This package features most functionalities needed for your SEO needs like meta fields, sitemap, robots.txt and much more.
MIT License
38 stars 28 forks source link

Canonical URL %CurrentUrl% breaks when custom URL provider is used #206

Closed philipdanielhayton closed 1 year ago

philipdanielhayton commented 1 year ago

Hi Patrick,

Using a custom URL provider and '%CurrentUrl%' in the Canonical URL is throwing an exception. There are two symptons:

1) It breaks the SEO tab on affected nodes 2) Using the <meta-fields></meta-fields> tag breaks the front end

The exception I'm getting is below. I've tested this on two separate Umbraco 11 projects and it happens on both. I've not tested it on Umbraco 10.

I can get around it for now by leaving the Canonical URL empty, or by hard coding a different value. It's not a deal breaker but would be awesome to get a fix.


System.UriFormatException: Invalid URI: The format of the URI could not be determined.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at System.Uri..ctor(String uriString)
   at SeoToolkit.Umbraco.MetaFields.Core.Common.Converters.SeoValueConverters.TextSeoValueConverter.Convert(Object value, IPublishedContent currentContent, String fieldAlias)
   at SeoToolkit.Umbraco.MetaFields.Core.Providers.DefaultMetaTagsProvider.<>c__DisplayClass12_0.<Get>b__2(ISeoField it)
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToArray()
   at SeoToolkit.Umbraco.MetaFields.Core.Providers.DefaultMetaTagsProvider.Get(IPublishedContent content, Boolean includeUserValues)
   at SeoToolkit.Umbraco.MetaFields.Core.Services.MetaFieldsService.MetaFieldsService.Get(IPublishedContent content, Boolean includeUserValues)
   at SeoToolkit.Umbraco.MetaFields.Core.Common.TagHelpers.MetaFieldsTagHelper.Process(TagHelperContext context, TagHelperOutput output)
.... lots more````
patrickdemooij9 commented 1 year ago

Hi @philipdanielhayton Sorry to leave your issue hanging here for two weeks. Are you able to show some of the code that you have in your content finder? Would love to see what sort of URL you are returning from it.

philipdanielhayton commented 1 year ago

Hi @patrickdemooij9,

Hey no problem brother. I've actually fixed the issue, turns out it was a gap in my understanding of how UrlProviders work. 🤦🏻‍♂️ I thought they only handled relative URLs, but I noticed that sometimes they can be absolute too, so I've added some code to handle both scenarios and it now works as expected 🥳

Sorry if you wasted any time on this.