ZioTino / Our.Umbraco.Skipper

An Umbraco package that lets you specify nodes and document types that will be excluded from Umbraco's URL generation.
https://ziotino.github.io/Our.Umbraco.Skipper/
MIT License
4 stars 3 forks source link

Problems with properties "umbracoUrlSkipper" & "umbracoHideSkipperWork" #5

Open hfloyd opened 1 year ago

hfloyd commented 1 year ago

Hi @ZioTino ! First, I want to thank you for porting this from Sotiris's v8 version. I really like using it. I am using this in a few Umbraco 10 sites. I've found that setting the doctypeAlias in the appsettings.json works very well.

Today I had a project requirement that certain nodes needed to be excluded from URLs, but others of the same doctype needed to be included, so I was happy to see you have added support for node-specific (not just doctype specific) configuration.

I added the two skipper properties to my doctype and set them both to TRUE for a node. When I published, the sub-nodes URLs were no longer including that segment - however they were showing multiple slashes in place of the excluded segment. For example, the site structure is:

Home
~ Products <-- This is the node I excluded
~~ Category
~~~ Product

originally, the URLs (without Skipper config) would be like "/products/category/" after the Skipper property exclusion, I was seeing URLs like this: "///category/"

Figuring the three slashes might be just because I hadn't republished everything, I published Home + all descendants, but once that was complete, I had a bigger issue - When I clicked on the "Products" node in the back-office, I got an error:

image


An error occurred
Index was outside the bounds of the array.

Exception Details
System.IndexOutOfRangeException, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e: Index was outside the bounds of the array.
Stacktrace
at Our.Umbraco.Skipper.SkipperUrlProvider.BuildUrl(IPublishedContent content, Uri current, UrlMode mode, String culture)
   at Our.Umbraco.Skipper.SkipperUrlProvider.GetUrl(IPublishedContent content, UrlMode mode, String culture, Uri current)
   at Umbraco.Cms.Core.Routing.UrlProvider.<>c__DisplayClass14_0.<GetUrl>b__1(IUrlProvider provider)
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at Umbraco.Cms.Core.Routing.UrlProvider.GetUrl(IPublishedContent content, UrlMode mode, String culture, Uri current)
   at Umbraco.Extensions.PublishedContentExtensions.Url(IPublishedContent content, IPublishedUrlProvider publishedUrlProvider, String culture, UrlMode mode)
   at Umbraco.Extensions.FriendlyPublishedContentExtensions.Url(IPublishedContent content, String culture, UrlMode mode)
   at Our.Umbraco.Skipper.SkipperContentFinder.<>c__DisplayClass4_0.<TryFindContent>b__0(IPublishedContent x)
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Our.Umbraco.Skipper.SkipperContentFinder.TryFindContent(IPublishedRequestBuilder request)
   at Umbraco.Cms.Core.Routing.PublishedRouter.FindPublishedContent(IPublishedRequestBuilder request)
   at Umbraco.Cms.Core.Routing.PublishedRouter.TryRouteRequest(IPublishedRequestBuilder request)
   at Umbraco.Cms.Core.Routing.PublishedRouter.RouteRequestAsync(IPublishedRequestBuilder builder, RouteRequestOptions options)
   at Umbraco.Extensions.UrlProviderExtensions.DetectCollisionAsync(ILogger logger, IContent content, String url, String culture, IUmbracoContext umbracoContext, IPublishedRouter publishedRouter, ILocalizedTextService textService, IVariationContextAccessor variationContextAccessor, UriUtility uriUtility)
   at Umbraco.Extensions.UrlProviderExtensions.GetContentUrlsByCultureAsync(IContent content, IEnumerable`1 cultures, IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, IContentService contentService, ILocalizedTextService textService, IVariationContextAccessor variationContextAccessor, ILogger logger, UriUtility uriUtility, IPublishedUrlProvider publishedUrlProvider)
   at Umbraco.Extensions.UrlProviderExtensions.GetContentUrlsAsync(IContent content, IPublishedRouter publishedRouter, IUmbracoContext umbracoContext, ILocalizationService localizationService, ILocalizedTextService textService, IContentService contentService, IVariationContextAccessor variationContextAccessor, ILogger`1 logger, UriUtility uriUtility, IPublishedUrlProvider publishedUrlProvider)
   at Umbraco.Cms.Web.BackOffice.Mapping.ContentMapDefinition.GetUrls(IContent source)
   at Umbraco.Cms.Web.BackOffice.Mapping.ContentMapDefinition.Map[TVariant](IContent source, ContentItemDisplay`1 target, MapperContext context)
   at Umbraco.Cms.Core.Mapping.UmbracoMapper.Map[TTarget](Object source, Type sourceType, MapperContext context)
   at Umbraco.Cms.Core.Mapping.UmbracoMapper.Map[TTarget](Object source, MapperContext context)
   at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.MapToDisplayWithSchedule(IContent content)
   at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.GetById(Int32 id)
   at lambda_method333(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

And if I clicked on subnodes (such as "category"), and clicked over to the "Info" area to view the URL, I'd get the same error.

hfloyd commented 1 year ago

I have some more information about this issue.

On a hunch today, I made a small change to the "Culture and Hostnames" for the two root-level Content nodes (sites) in the umbraco install.

Since I am working locally, I had originally used a "folder" type of hostname (ex: "/site-a" and "/site-b"), and was receiving the errors I mentioned above. I changed the hostnames to "domain-style" hostnames (ex: "site-a.local" and "site-b.local") and the error went away.

So, it seems this issue is specific to folder-type hostnames being used.

archimedecreativa commented 1 year ago

Hi @hfloyd Can you update and retry? Thank you!

hfloyd commented 1 year ago

Hi @archimedecreativa I updated the project in question to 1.1.4, but get a similar error if I change the hostname back to "/site-a":

image